Command-Line Arguments

Wikipedia: Command-line interface
os.args() returns the full argument list. The first element is the interpreter name, the second is the script path, and anything after that is user-supplied.

fmt := import("fmt")
os := import("os")
fmt.println("program: ", args[0])
fmt.println("script: ", args[1])
if len(args) > 2 {
    fmt.println("first user arg: ", args[2])
} else {
    fmt.println("(no user args — try: tengo script.tengo hello)")
}

try it

["tengo", "playground.tengo"]
program: tengo
script: playground.tengo
(no user args — try: tengo script.tengo hello)
loading…