So I have script that takes file from user with option -y or -n and -d is required script runs ./example.sh -d file -y or -n variable
file=""
I need to do validation on if the user did not pass file in for example
./example.sh -y --- it should give error "must provide file"`
./example.sh -n --- it should give error "must provide file"`
./example.sh -d --- it should give error "must provide file"
./example.sh -y -n --- it should give error "must provide file"
i came up with this but its not working #checking if the file is provided
if [ $file -eq 1 ]; then
echo "No file provided"
exit 1
fi
# Does the file exist
which works for checking if the file exists but it only check if the file in there
if [[ ! -f $file ]]; then
echo
echo "Error: The file $file does not exist."
exit 1
fi