From cc18a6cdf1050505313f26dca41b5dc42cb09947 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 7 Mar 2024 13:11:36 +0000 Subject: [PATCH] Check validity of arguments --- griddle | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/griddle b/griddle index c6ac025..aef416d 100755 --- a/griddle +++ b/griddle @@ -1,18 +1,30 @@ #!/bin/sh +set -e + main() { if test "$#" -ne 2; then - echo "Usage: griddle " + printf "Usage: griddle \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" }