Testing a command's stored exit status with var=$?; [[ $var ]] is always true, whether 0 or 1
问题 Consider: true; run_backup=$? if [[ $run_backup ]]; then echo "The user wants to run the backup" fi ...and... false; run_backup=$? if [[ $run_backup ]]; then echo "The user wants to run the backup" fi The user wants to run the backup is emitted whether run_backup has 0 (success) or 1 (false)! What's going on here? (My real command, instead of true or false , is of the form zenity --question --text "..." ). 回答1: [[ $run_backup ]] is not a Boolean check; it fails only if its argument is an