Let's say I have a C program, and I run it from bash:
$ ./a.out 123 *
The program would output all the command line arguments, but it will show these instead:
Argument 1: 123 Argument 2: a.out
What can I do in my program to fix this?
Let's say I have a C program, and I run it from bash:
$ ./a.out 123 *
The program would output all the command line arguments, but it will show these instead:
Argument 1: 123 Argument 2: a.out
What can I do in my program to fix this?
You can quote it in the shell
./a.out 123 '*'
There is nothing you can do in your program, because the * expansion is done by the shell (in contrast to Windows, where it's done by the program).
The shell is replacing the asterisk with the name of each file in the directory.
To pass a literal asterisk, you should be able to escape it:
$ ./a.out 123 \*
This doesn't have anything to do with your program.
The *
is a wildcard in Bash, it means "all files in the current directory". If you want to pass an asterisk as an argument to your program, you do it the same way you do it with every other program: you escape it with a backslash or quote it.
Another option is to use set -f to turn off expansion. compare:
echo *
vs
set -f
echo *