Quantcast
Channel: What is the difference between $* and $@? - Unix & Linux Stack Exchange
Browsing all 12 articles
Browse latest View live

Answer by isomorphismes for What is the difference between $* and $@?

One of the answers says $* (which I think of as a "splat") is rarely useful. I search google with G() { IFS='+' ; w3m "https://encrypted.google.com/search?q=$*" ; } Since URL’s are often split with a...

View Article



Answer by Gilles 'SO- stop being evil' for What is the difference between $*...

Short answer: use "$@" (note the double quotes). The other forms are very rarely useful. "$@" is a rather strange syntax. It is replaced by all the positional parameters, as separate fields. If there...

View Article

Answer by cuonglm for What is the difference between $* and $@?

Here is a simple script to demonstrates the difference between $* and $@: #!/bin/bash test_param() { echo "Receive $# parameters" echo Using '$*' echo for param in $*; do printf '==>%s<==\n'...

View Article

Answer by Mikel for What is the difference between $* and $@?

When they are not quoted, $* and $@ are the same. You shouldn't use either of these, because they can break unexpectedly as soon as you have arguments containing spaces or wildcards. "$*" expands to a...

View Article

Answer by Carlos Campderrós for What is the difference between $* and $@?

The difference is important when writing scripts that should use the positional parameters in the right way... Imagine the following call: $ myuseradd -m -c "Carlos Campderrós" ccampderros Here there...

View Article


Answer by Stéphane Gimenez for What is the difference between $* and $@?

Talking about differences between zsh and bash: With quotes around $@ and $*, zsh and bash behave the same, and I guess the result is quite standard among all shells: $ f () { for i in "$@"; do echo...

View Article

Answer by Wojtek Rzepala for What is the difference between $* and $@?

The code you provided will give the same result. To understand it better, try this: foo () { for i in "$*"; do echo "$i" done } bar () { for i in "$@"; do echo "$i" done } The output should now be...

View Article

Answer by rush for What is the difference between $* and $@?

* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a sin‐ gle word with the value of each parameter separated by the first...

View Article


What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common shells as well. If you...

View Article


Answer by Bernd for What is the difference between $* and $@?

File Name: try#!/bin/bashstar() { echo echo '--- $* no quotes' for Field in $*; do echo $Field done}star_quote() { echo echo '--- $* with quotes' for Field in "$*"; do echo $Field done}dollar() { echo...

View Article

Answer by Sonia Hamilton for What is the difference between $* and $@?

"$*" has few uses, the other answers cover why.Here's a neat example of using "$*" to just "print everything" when doing error handling:error () { printf '%s\n'"$*" exit 1}This script demonstrates the...

View Article

Answer by x-yuri for What is the difference between $* and $@?

Most of the time you want $@. But a use I've found... Let's say you're creating a script that creates another script (e.g. to be executed on a remote server). You have an array with commands, and you...

View Article
Browsing all 12 articles
Browse latest View live




Latest Images