Linked Questions

41
votes
4answers
69k views

What's the difference between $@ and $* [duplicate]

According to this page, $@ and $* do pretty much the same thing: The $@ holds list of all arguments passed to the script. The $* holds list of all arguments passed to the script. After searching ...
7
votes
4answers
10k views

what does $* mean in shell [duplicate]

What does $* mean in shell? I have code two function, run_command and run_test, they are called like this: if [ -n "`echo ${GOAT_COMMANDS} | grep $1`" ]; then run_command $* else run_test $* fi ...
8
votes
3answers
2k views

In bash, what is the safest way to pass variables to another program — $* or $@? [duplicate]

Can someone explain to me in a concise way what the difference between these two vars is? What is the safest way to pass variables to another program? E.g. #! /bin/bash # do stuff # pass ...
3
votes
2answers
31k views

What is the meaning of $* in a shell script? [duplicate]

In a shell script file i saw "$*", what does it mean and when we have to use it?
7
votes
7answers
282 views

What is the purpose of having two variables ($@,$*) to transmit the arguments of a command into a script? [duplicate]

I have read of the special variables used in a script $@ and $*. As far as I understand, the arguments used while executing the script are stored into two special variables, once all arguments into $@ ...
1
vote
2answers
163 views

@ and * in bash loop [duplicate]

I found the following two loops yield the same output. Can you help me to understand what the differences are between the @ and * in this particular case? #!/bin/bash ips=(8.8.8.8 8.8.4.4) for ip ...
12
votes
0answers
417 views

Should I use $* or $@? [duplicate]

Which one of $* or $@ is better to use (in array syntax,command line parameters, etc.) to avoid any bugs/problems in code? Or it does not make any difference?
0
votes
2answers
107 views

Different behaviour of eval “ command \”$@\“ ”, “$@”, and “$(echo $@)” when used as arguments [duplicate]

I would like to pass multiple arguments to the Tor browser (firefox) programatically through a function arbitrarily entitled tor. This is so as to command tor search terms and voila! My search terms. ...
0
votes
3answers
49 views

`$@` vs. `$*` behavior [duplicate]

The bash manual says: Regarding: $* When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special ...
2
votes
0answers
55 views

Bash: Special variables $@ vs. $* in For Loop [duplicate]

Using $@ instead of $* would preserve quoting. Consider the following script: #!/bin/bash # Test.sh for arg in $@ do echo "I found the argument $arg" done ./Test.sh "One Two Three" I reach the ...
2
votes
0answers
41 views

When would you use $* instead of $@ in Bourne shells? [duplicate]

In Bourne shell and its offshoots like Bash, I believe the only difference between $* and $@ is that $@ expands in double quotes so that each argument ends up as a single word even if it contained ...
262
votes
4answers
203k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
29
votes
9answers
31k views

How to print the longest line in a file?

I'm looking for the simplest method to print the longest line in a file. I did some googling and surprisingly couldn't seem to find an answer. I frequently print the length of the longest line in a ...
15
votes
1answer
6k views

Bash: slice of positional parameters

How can I get a slice of $@ in Bash without first having to copy all positional parameters to another array like this? argv=( "$@" ) echo "${argv[@]:2}";
12
votes
2answers
807 views

What is the data structure of $@ in shell?

We usually use $@ to represent all of argument except $0. However, I don't know what data structure $@ is. Why it behave differently with $* when including in double quote, could anyone give me a ...

15 30 50 per page