BASIC · lesson 25 of 30 · Tools for the NASRun a command
system$ gives back what a command printed, system gives back its exit code.
25-run-command.yab Download 25-run-command.yab
rem system$ runs a command and gives back what it printed;
rem system gives back its exit code
kernel$ = system$("uname -s")
print "kernel: ", left$(kernel$, len(kernel$) - 1)
code = system("grep -q ERROR nas.log")
if code = 0 then
print "the log has errors"
else
print "no errors in the log"
endif
dim line$(1)
n = token(system$("ls photos"), line$(), chr$(10))
print n, " files in photos, the first is ", line$(1)
Terminal
$ yabasic 25-run-command.yab
kernel: Linux
the log has errors
6 files in photos, the first is beach.jpgExercise
Print how many lines of the log contain WARN.