I'd like to use arguments from file as command-line arguments for some commands like gcc or ls.
For example gcc -o output -Wall -Werro
as file consist of:
-o output -Wall -Werro
Used for gcc command-line call.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.
To look at the contents of a text-based configuration file, use cat or less . Generally, you'll use less because it has more options (such as searching). To use less , enter the command name followed by the name of the file you want to view. The first page of text fills the window.
A command line argument is simply anything we enter after the executable name, which in the above example is notepad.exe. So for example, if we launched Notepad using the command C:\Windows\System32\notepad.exe /s, then /s would be the command line argument we used.
Some programs use the "@" semantics to feed in args from a file eg. gcc @argfile
Where, for gcc, argfile contains options
-ansi
-I/usr/include/mylib
This can be nested so that argfile can contain
-ansi
-I/usr/include/mylib
@argfile2
http://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Overall-Options.html#Overall-Options
You can use xargs
:
cat optionsfile | xargs gcc
Edit: I've been downvoted because Laurent doesn't know how xargs
works, so here's the proof:
$ echo "-o output -Wall -Werro" > optionsfile
$ cat optionsfile | xargs -t gcc
gcc -o output -Wall -Werro
i686-apple-darwin10-gcc-4.2.1: no input files
The -t
flag causes the command to be written to stderr
before executing.
gcc `cat file.with.options`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With