0

so i am doing a shell script and am trying to figure out how to do this safe guard function:

if ! [[ -e "$@" ]]; then
    echo"Not a file!"
    exit 0
fi

my ideia is to check every input for file. so when i call the script: ./scriptname file1.txt file2.tar NOTfile4 it will output NOT a file

1 Answers1

1

thanks guys! did the loop and it worked. heres what i did if anyone who has the same problem:

for input in "$@"; do
if ! [ -e "$input" ]; then
    echo "Not a file!"
    exit 0
fi
done
  • 2
    That should probably be `exit 1`; Non-zero exit statuses indicate errors. If every file exists, your script will exit 0 anyway. – chepner Mar 23 '18 at 19:26