$ * in bash scripts

Can someone tell me what $* means in bash scripts?

I tried to do a google search for this, but found only around $0 , $1 , etc.

So, if you have a link to this, welcome.

Thanks!

+6
source share
7 answers

See this page:

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

The behavior of $ * and $@ when $ IFS is empty depends on + on which Bash or sh is running. Therefore, it is impractical to depend on this "function" in the script.

+4
source

On the man page:

* Expands to positional parameters, starting with one. When expansion occurs in double quotes, it expands to one word with the value of each parameter separated by the first character of the IFS special variable. That is, " $* " is equivalent to " $1 c $2 c ...", where c is the first character of the value of the IFS variable. If IFS is not specified, the parameters are separated by spaces. If IFS is null, the parameters are combined without intermediate separators.

Thus, it is equivalent to all positional parameters with slightly different semantics depending on whether it is in quotation marks.

+8
source

All arguments are passed to the script, except for word splitting. You almost always want to use " $@ " . And all this on the bash(1) man page.

+3
source

His list of arguments provided on the command line will be a script. $ 0 will be the name of the script.

+3
source

You can use the symbolhound search engine to search for codes that google is not looking for.

Click here for your request.

+3
source

This is a string separated by a space of all arguments. For example, if $1 is "hello" and $2 is "world", then $* is "hello world". (If $ IFS is not set, then this is a $ IFS delimited string.)

+1
source

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

Example:

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

The output of the above script:

 100 Count Value = 100 
0
source

Source: https://habr.com/ru/post/907756/


All Articles