Check validity of arguments
This commit is contained in:
parent
54b22aa38f
commit
cc18a6cdf1
16
griddle
16
griddle
|
@ -1,18 +1,30 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
main() {
|
||||
if test "$#" -ne 2; then
|
||||
echo "Usage: griddle <inputfile> <outputfile>"
|
||||
printf "Usage: griddle <inputfile> <outputfile>\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
inputfile="$1"
|
||||
if ! test -e "$inputfile"; then
|
||||
echo "Input file $inputfile does not exist."
|
||||
printf "Input file %s does not exist.\n" "$inputfile"
|
||||
return 2
|
||||
fi
|
||||
|
||||
outputfile="$2"
|
||||
if test -e "$outputfile"; then
|
||||
printf "Output file $outputfile already exists. Overwrite? (y/N) "
|
||||
read response
|
||||
if ! test "$response" = "y" -o "$response" = "Y"; then
|
||||
printf "Not overwriting $outputfile.\n"
|
||||
return 0
|
||||
else
|
||||
printf "Overwriting $outputfile.\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$inputfile" "$outputfile"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue