NASutils Knowledge BaseUnofficialPolski

BASIC · lesson 17 of 30 · Data, functions and the command lineRead the command line

peek("argument") counts the words after the program's name and peek$("argument") takes the next one.

Programming on the NAS › BASIC in 30 lessons

17-arguments.yab Download 17-arguments.yab

rem peek("argument") counts the words after the program's name,
rem peek$("argument") takes the next one
count = peek("argument")
if count = 0 then
  print "usage: yabasic 17-arguments.yab NAME..."
  exit 2
endif

while peek("argument") > 0
  print "Hello, ", peek$("argument")
wend
print count, " names"

Terminal

$ yabasic 17-arguments.yab Ann "Jan Example"
Hello, Ann
Hello, Jan Example
2 names
$ yabasic 17-arguments.yab; echo "exit code $?"
usage: yabasic 17-arguments.yab NAME...
exit code 2

Exercise

Add up all numbers given as arguments.