所以我需要让它说这个人不在这个类里。好像是跳过了我的else语句。cut -d ',' -...
if [ $# == 1 ]; then
if grep "$1" /acct/common/CSCE215 | cut -d ',' -f1-3 | tr ',' ' '; then
true
else
echo "Sorry that person is not in CSCE215 this semester"
fi
else
echo "Command line arguments are not equal to 1"
echo "$#"
fi
The exit code of the piped commands is the exit code of the last one (Use tr
option in your script to break piping if one of the commands failed.0
Example:
So your script could be:set -o pipefail
PS: Use
to restore the usual behavior.
$ echo foo | grep bar | tr o a ; echo $?
0
$ set -o pipefail ; echo foo | grep bar | tr o a ; echo $?
1
set -o pipefail
if [ $# -eq 1 ]; then
if grep "$1" /acct/common/CSCE215 | cut -d ',' -f1-3 | tr ',' ' '; then
true
else
echo "Sorry that person is not in CSCE215 this semester"
fi
else
echo "Command line arguments are not equal to 1"
echo "$#"
fi
set +o pipefail
所以我需要让它说这个人不在这个班级里,它好像跳过了我的 else 语句。它好像跳过了我的 else 语句,有什么问题吗?有什么问题吗? if [ $# == 1 ]; then if grep "$1" acctcommonCSCE215。