BASIC · lesson 18 of 30 · Data, functions and the command lineReport success or failure
exit N ends the program with a code. The shell reads it with && and ||.
18-exit-codes.yab Download 18-exit-codes.yab
rem The exit code tells the shell how it went: 0 is fine
free = val(peek$("argument"))
if free < 10 then
print "low: ", free, " percent free"
exit 1
endif
print "fine: ", free, " percent free"
Terminal
$ yabasic 18-exit-codes.yab 35 && echo "start the backup"
fine: 35 percent free
start the backup
$ yabasic 18-exit-codes.yab 4 || echo "do not start it, code $?"
low: 4 percent free
do not start it, code 1Exercise
Exit with 2 if the argument is missing.