13

What does $* mean in bash scripting?

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

9 Answers 9

10

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.

Sign up to request clarification or add additional context in comments.

Comments

4

See this page:

http://tldp.org/LDP/abs/html/internalvariables.html#IFSEMPTY

The behavior of $* and $@ when $IFS is empty depends + on which Bash or sh version being run. It is therefore inadvisable to depend on this "feature" in a script.

Comments

4

It's all the arguments passed to the script, except split by word. You almost always want to use "$@" instead. And it's all in the bash(1) man page.

Comments

4

Its the list of arguments supplied on the command line to the script .$0 will be the script name.

Comments

3

It's a space separated string of all arguments. For example, if $1 is "hello" and $2 is "world", then $* is "hello world". (Unless $IFS is set; then it's an $IFS separated string.)

Comments

2

You can use symbolhound search engine to find codes that google will not look for.

For your query click here

Comments

0

If you see $ in prefix with anything , it means its a variable. The value of the variable is used.

Example:

count=100
echo $count
echo "Count Value = $count"

Output of the above script:

100
Count Value = 100

1 Comment

Though the statement you make is correct, the question was "What is $* mean?
0

As an independent command it doesn't have any significance in bash scripting. But, as per usage in commands, it's used to indicate common operation on files / folders with some common traits.

and with grep used to represent zero or more common traits in a command.

Comments

-1

Well,such case when you find number of average or total number.

$# number of argument to pass in the number $* number of all argument to pass

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.