There are two exit codes and therefore, two possible points of failure:
doas
and the
command
.
Wrapping an exit code test in a loop does what I expect -- until doas(1) succeeds (exit 0), but the command fails (exit >0). The command failure is reported correctly, but the program is stuck in an infinite loop because the exit code for the command is not zero.
To test this, I made a simple script:
Code:
# Write a trace for each command.
set -x
doas ls ~/NoDirectory
until [ $? -eq 0 ]
do
doas ls ~/NoDirectory
done
echo 'Script successfully completed!'
OUTPUT:
# + doas ls /home/gustaf/NoDirectory
# doas (gustaf...) password:
# ls: /home/gustaf/NoDirectory: No such file or directory
# + [ 1 -eq 0 ]
# + doas ls /home/gustaf/NoDirectory
# doas (gustaf...) password:
# ls: /home/gustaf/NoDirectory: No such file or directory
# + [ 1 -eq 0 ]
# + doas ls /home/gustaf/NoDirectory
# doas (gustaf...) password
The loop is supposed to be for doas(1) only. I need some way to report an error and exit the script if the command fails.