I am trying to run a C program in Ubuntu via command prompt, I can run successfully using
./aaa<arg_file.txt
Content of arg_file.txt
a
bb
ccc
It displays the result successfully, but this time I do not want to use the txt file to pass the parameters, instead I want to pass all the arguments using one single line, how can I represent the next line character in the argument field?
Thanks all for the advice!
If your shell is Bash or compatible, use the <<[SENTINEL]
syntax:
h2co3-macbook:~ h2co3$ cat <<EOF
> abc
> def
> ghi
> EOF
abc
def
ghi
h2co3-macbook:~ h2co3$
Just pass with spaces inbetween like
./aaa a bb ccc
In C program, argv[0]
will be ur exe name. then
argv[1] = "a"
argv[2] = "bb"
argv[3] = "ccc"
will be there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.