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