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

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

$
0
0

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    echo '--- $@ no quotes'    for Field in $@; do        echo $Field    done}dollar_quote() {    echo    echo '--- $@ with quotes'    for Field in "$@"; do        echo $Field    done}#-----------------------echostar $*star_quote "$*"dollar $@dollar_quote "$@"echoexit

Command:

./try 1 2 3 "4 and 5"

Results:

--- $* no quotes1234and5--- $* with quotes1 2 3 4 and 5--- $@ no quotes1234and5--- $@ with quotes1234 and 5

Viewing all articles
Browse latest Browse all 12

Trending Articles