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?
It's a space separated string of all arguments. For example, if $1 is "hello" and $2 is "world", then $* is "hello world".
It means all the arguments passed to the script or function, split by word.
To replace a substring with new value in a string in Bash Script, we can use sed command. sed stands for stream editor and can be used for find and replace operation. We can specify to sed command whether to replace the first occurrence or all occurrences of the substring in the string.
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 \*
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