FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 12-05-2009, 07:24 AM
Kaushal Shriyan
 
Default special variable $@ and $*

Hi,

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

I did not understand the difference between $@ and $* special variable.
Please explain me with an example.

Thanks,

Kaushal

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 12-05-2009, 08:03 AM
Tom H
 
Default special variable $@ and $*

> http://tldp.org/LDP/abs/html/internalvariables.html#APPREF
> I did not understand the difference between $@ and $* special variable.
> Please explain me with an example.

./script "name with spaces"

For the above
$* is expanded to three arguments, "name", "with", and "spaces"
$# is expanded to one argument, "name with spaces"

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 12-05-2009, 08:16 AM
Kaushal Shriyan
 
Default special variable $@ and $*

On Sat, Dec 5, 2009 at 2:33 PM, Tom H <tomh0665@gmail.com> wrote:
>> http://tldp.org/LDP/abs/html/internalvariables.html#APPREF
>> I did not understand the difference between $@ and $* special variable.
>> Please explain me with an example.
>
> ./script "name with spaces"
>
> For the above
> $* is expanded to three arguments, "name", "with", and "spaces"
> $# is expanded to one argument, "name with spaces"
>
Hi Tom,

#!/bin/bash
echo "alice: $*"
echo "alice: $@"
echo "$@: $1 $2"
echo "$# arguments"
The above script name is test.sh

hosttest ~ # ./test.sh alice in wonderland
alice: alice in wonderland
alice: alice in wonderland
alice in wonderland: alice in
3 arguments

Still not clear as per the above output. both prints same. Please
guide with some example or in context with my bash snippet.

Thanks and Regards,

Kaushal

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 12-05-2009, 08:20 AM
Loïc Grenié
 
Default special variable $@ and $*

2009/12/5 Kaushal Shriyan <kaushalshriyan@gmail.com>:
> Hi,
>
> http://tldp.org/LDP/abs/html/internalvariables.html#APPREF
>
> I did not understand the difference between $@ and $* special variable.
> Please explain me with an example.

If your script is script:

#!/bin/sh
ls $*
ls $@
ls "$*"
ls "$@"

then

script first "second long" and third

would call ls with respectively:

ls first second long and third (5 args)
ls first second long and third (5 args)
ls "first second long and third" (1 arg)
ls first "second long" and third (4 args -- the same you gave to the script)

Hope this helps,

Loïc

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 03:51 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org