Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 55 / 68

Receiving command-line arguments

This lesson covers receiving command-line arguments with Julia's ARGS, with the aim of passing values in from outside at run time.

The ARGS array holds the command-line arguments. It is the essential mechanism for a script whose options can be switched at run time.

The sample code checks whether arguments were passed with length(ARGS) > 0 ? ARGS[1] : "Anonymous", using the first argument as the name if so and a fallback if not.

A common early stumble is reaching for an argument without checking how many arrived and getting an error. Check the count with length(ARGS) first.

In professional work, this extends to automation scripts for data analysis that branch on the values passed in at run time.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)