Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$* in bash scripting

Tags:

bash

scripting

Can anybody tell me what does $* mean in bash scripting?

I tried to search on google for it, but I found only about $0, $1 and so on.

So, if have a link for this, is welcome.

Thanks!

like image 766
artaxerxe Avatar asked Feb 06 '12 09:02

artaxerxe


People also ask

What is $* in bash script?

$* and $@ are special bash parameters and if used without double quotes then both will behave identical i.e. they will provide the list of positional parameter starting from the first parameter $1 and each of those will be separated by space.

What is $@ and $* in shell script?

• $* - It stores complete set of positional parameter in a single string. • $@ - Quoted string treated as separate arguments. • $? - exit status of command.

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

What is difference between $@ and $* in shell?

$0 Stores the first word of the entered command (the name of the shell program). $* Stores all the arguments that were entered on the command line ($1 $2 ...). "$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...).


1 Answers

From the man page:

* 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.

So it is equivalent to all the positional parameters, with slightly different semantics depending on whether or not it is in quotes.

like image 86
Mat Avatar answered Oct 31 '22 11:10

Mat