I'm writing a bash script to organise a .txt file, of which is loaded with the bash script using the command line parameter:
bash ./myScript.sh textfile.txt
I have an if statement (below, non-functional) that's supposed to detect if the .txt file exists in the same directory. If it does, it confirms it with the user and the script continues. If it doesn't exist, the script is supposed to continually check if the user's input is an existing file in the working directory before continuing.
Here's what I have so far:
#CS101 Assignment BASH script
CARFILE=$1
wc $CARFILE
if [ -f $CARFILE ]
then
echo "$CARFILE exists, please continue"
else
echo "This file does not exist, please enter the new filename and press [ENTER]"
read CARFILE
echo "We have detected that you're using $CARFILE as your cars file, please continue."
fi
It simply outputs: exists, please continue if you don't run it with a .txt (ie bash jag32.sh instead of bash jag32.sh textfile.txt).
Can anyone help out please?
Thanks.
$CARFILE?