Mohammedz.com

For Linux and Shell scripting.

Difference between $* and $@

Leave a comment


Run the script below and feel the difference 😉

shell]$ cat input
#! /bin/bash

echo “$# inputs”
echo “”
echo ‘”$@” output’
for arg in “$@”; do
echo $arg
done
echo “”
echo ‘$@ output’
for arg in $@; do
echo $arg
done
echo “”
echo ‘”$*” output’
for arg in “$*”; do
echo $arg
done
echo “”
echo ‘$* output’
for arg in $*; do
echo $arg
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shell]$ ./input a b ‘c d’
3 inputs

“$@” output
a
b
c d

$@ output
a
b
c
d

“$*” output
a b c d

$* output
a
b
c
d
shell]$

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s