[英]Multiple conditions on IF with Shell Script
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.我的一位同事检查了一个文件处理脚本,该脚本从我们的数据库中提取数据并将其放在 some.txt 文件中。
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.现在,我正在尝试生成 File_ID 等于 11 的文件,但我得到了错误。 What's wrong in this statement?
这个说法有什么问题?
I would use a case
statement instead along with an if
statement:我会使用
case
语句和if
语句:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.