Access command line arguments in Julia

后端 未结 4 1589
别那么骄傲
别那么骄傲 2021-02-05 00:34

When I type in

$ julia myprog.jl foo bar baz

Where in my code can I go to access the strings \"foo\", \"bar\", \"baz\" ?

4条回答
  •  星月不相逢
    2021-02-05 00:48

    Ah, more web-searching led to the right answer. The keyword ARGS::Array{ASCIIString} holds command line arguments

    Here is a simple example

    # cli.jl
    
    print(map(x->string(x, x), ARGS))  # Concatenate each arg onto itself and print
    

    Lets test it at the command line:

    $ julia cli.jl a b c
    aa
    bb
    cc
    

提交回复
热议问题