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: 3foreach 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 .

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.