Check validity of arguments
This commit is contained in:
parent
54b22aa38f
commit
cc18a6cdf1
16
griddle
16
griddle
|
@ -1,18 +1,30 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if test "$#" -ne 2; then
|
if test "$#" -ne 2; then
|
||||||
echo "Usage: griddle <inputfile> <outputfile>"
|
printf "Usage: griddle <inputfile> <outputfile>\n"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
inputfile="$1"
|
inputfile="$1"
|
||||||
if ! test -e "$inputfile"; then
|
if ! test -e "$inputfile"; then
|
||||||
echo "Input file $inputfile does not exist."
|
printf "Input file %s does not exist.\n" "$inputfile"
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
outputfile="$2"
|
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"
|
echo "$inputfile" "$outputfile"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue