Check validity of arguments

This commit is contained in:
The Magician 2024-03-07 13:11:36 +00:00
parent 54b22aa38f
commit cc18a6cdf1
1 changed files with 14 additions and 2 deletions

16
griddle
View File

@ -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"
} }