Subshell evaluations are not exempt from errexit, so if a command is not available, `which` will fail and exit the script as a whole. This causes the helpful error messages to not be printed if they are tacked on using a `$?` comparison. Resolve the issue by using chains of logical operators, which are not subject to the effects of errexit.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -6,27 +6,24 @@ if [ `id -u` -ne 0 ]; then · 5 unmodified lines | ||
| 6 | 6 | exit 1 |
| 7 | 7 | fi |
| 8 | 8 | |
| 9 | −SF=`which setfiles` | |
| 10 | −if [ $? -eq 1 ]; then | |
| 9 | +SF=`which setfiles` || { | |
| 11 | 10 | echo "Could not find setfiles" |
| 12 | 11 | echo "Do you have policycoreutils installed?" |
| 13 | 12 | exit 1 |
| 14 | −fi | |
| 13 | +} | |
| 15 | 14 | |
| 16 | −CP=`which checkpolicy` | |
| 17 | −if [ $? -eq 1 ]; then | |
| 15 | +CP=`which checkpolicy` || { | |
| 18 | 16 | echo "Could not find checkpolicy" |
| 19 | 17 | echo "Do you have checkpolicy installed?" |
| 20 | 18 | exit 1 |
| 21 | −fi | |
| 19 | +} | |
| 22 | 20 | VERS=`$CP -V | awk '{print $1}'` |
| 23 | 21 | |
| 24 | −ENABLED=`which selinuxenabled` | |
| 25 | −if [ $? -eq 1 ]; then | |
| 22 | +ENABLED=`which selinuxenabled` || { | |
| 26 | 23 | echo "Could not find selinuxenabled" |
| 27 | 24 | echo "Do you have libselinux-utils installed?" |
| 28 | 25 | exit 1 |
| 29 | −fi | |
| 26 | +} | |
| 30 | 27 | |
| 31 | 28 | if selinuxenabled; then |
| 32 | 29 | echo "SELinux is already enabled" |