Getting input from command-line arguments

Command-line arguments are captured in the system/script/args word. It is one string in which all arguments are stored, separated by a space:

;-- see Chapter10/args.red:
print
system/script/args ;== "78 A Red"
type? system/script/args ;== string!
args: split system/script/args " " ;== ["78" "A" "Red"]
print ["Number of command-line arguments:" length? args]
;== Number of command-line arguments: 3
foreach arg args [
print arg
]
; 78
; A
; Red

We can use split to obtain the separated arguments in an args series, and start using them.

To see the output, start the program with red args.red 78 A Redor after compiling with red -r, start it with: ./args 78 A Red .

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.103.5