Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does $* mean in a shell script

What does $* exactly mean in a shell script?

For example consider the following code snippet

$JAVA_HOME/bin/java/com/test/Testclass $*
like image 538
Subin_Learner Avatar asked Sep 13 '12 19:09

Subin_Learner


People also ask

What does $* mean in bash?

It's a space separated string of all arguments. For example, if $1 is "hello" and $2 is "world", then $* is "hello world".

What is $@ and $* in shell script?

"$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...). So basically, $# is a number of arguments given when your script was executed. $* is a string containing all arguments. For example, $1 is the first argument and so on.

What is significance of $* in argument passed to the script?

If a script receives two arguments, $* is equivalent to $1 $2. All the arguments are individually double quoted. If a script receives two arguments, $@ is equivalent to $1 $2.

What is the role of $0 $@ $* variable is shell script?

If the $0 special variable is used within a Bash script, it can be used to print its name and if it is used directly within the terminal, it can be used to display the name of the current shell.


2 Answers

It means all the arguments passed to the script or function, split by word.

It is usually wrong and should be replaced by "$@", which separates the arguments properly.

like image 130
Ignacio Vazquez-Abrams Avatar answered Oct 11 '22 07:10

Ignacio Vazquez-Abrams


It's easy to find answer by yourself: man bash/\$\*:

Special Parameters

The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.

  • Expands to the positional parameters, starting from one. 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 variable. That is, "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators.
like image 44
ДМИТРИЙ МАЛИКОВ Avatar answered Oct 11 '22 09:10

ДМИТРИЙ МАЛИКОВ