A coworker of mine made this check for a file processing script which extracts data from our database and put it on some.txt files.
if [ $File_ID < 4 ] || [ $File_ID > 64 ] || [ $File_ID -eq 60 ] && [ $File_ID != 0 ] && [ $File_ID != 1 ]; then
Rules:
Right now, I'm trying to generate the file with File_ID equal to 11, but I'm getting false. What's wrong in this statement?
I would use a case
statement instead along with an if
statement:
if [ "$File_ID" -lt 0 ] || [ "$File_ID" -gt 64 ]; then
printf 'File_ID %d out of range\n' "$File_ID"
exit 1;
fi
case $File_ID in
0) extract-files ;;
1) printf "You didn't say what to do with 1\n" >&2; exit 1 ;;
2|3|60) printf 'Error\n' >&2; exit 1 ;;
*) printf 'Pass\n' ;;
esac
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.