Re: What's the meaning of "echo $@"?
$@ returns the arguments to the script, similar to $* The following bash script will show the differences. x- myargs.sh -- #!/bin/bash # myargs.sh IFS=";" echo "$@" echo "$*" echo $@ echo $* echo "$# arguments" exit 0 x end myargs.sh - -- * For God so loved the world that He gave his only begotten Son, * * that whoever believes in Him should not perish...John 3:16 * -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: What's the meaning of "echo $@"?
On Mon, May 27, 2002 at 12:17:27PM +0930, Tom Cook wrote: | On 0, Squirrel <[EMAIL PROTECTED]> wrote: | > | [implied question] | > | > What's the meaning of "echo $@"? | | So if a script just has 'echo $@' in it, then it is functionally | equivalent to 'echo' (except doesn't have the command line options, | obviously). Not true -- the contents of $@ is expanded first, then sent to the command. If you want to be safe and ensure the the "data" isn't accidentally interpreted as arguments you need 'echo -- $@'. Test it out and see (also compare the differences between using ash and bash) : $ cat /tmp/echo.sh #!/bin/sh echo $@ $ /tmp/echo.sh -e 'bar\nfoo' -e bar foo $ /tmp/echo.sh 'bar\nfoo' bar foo $ cat /tmp/echo.sh #!/bin/bash echo $@ $ /tmp/echo.sh 'bar\nfoo' bar\nfoo $ /tmp/echo.sh -e 'bar\nfoo' bar foo $ -D -- (E)ventually (M)allocs (A)ll (C)omputer (S)torage GnuPG key : http://dman.ddts.net/~dman/public_key.gpg pgpfB1a5lAtKv.pgp Description: PGP signature
Re: What's the meaning of "echo $@"?
On 0, Squirrel <[EMAIL PROTECTED]> wrote: > [implied question] > > What's the meaning of "echo $@"? > In a shell script, $@ contains all the arguments to the script (NOT including the name of the script itself, unlike argv in C). So if a script just has 'echo $@' in it, then it is functionally equivalent to 'echo' (except doesn't have the command line options, obviously). Note that if you 'shift' the arguments then that cuts the front one off what $@ reports. Tom -- Tom Cook Information Technology Services, The University of Adelaide "There are few things more satisfying than seeing your children have teenagers of their own." - Doug Larson Get my GPG public key: https://pinky.its.adelaide.edu.au/~tkcook/tom.cook-at-adelaide.edu.au pgp16R93BYTch.pgp Description: PGP signature
Re: What's the meaning of "echo $@"?
On Mon, May 27, 2002 at 10:25:28AM +0800, Squirrel wrote: where's the question? oh, it's in the subject. how about putting the message in the message? The question was : What's the meaning of "echo $@"? To start with, 'echo' is a command. Depending on your shell it is either built-in or it is /bin/echo (in bash it is built in). It is explained in the 'echo' manpage (if using /bin/echo) or the 'bash' manpage (if using bash's built-in echo). The "$@" part is an argument to echo. Names beginning with $ are shell variables and are expanded by the shell before the application sees them. In the bash manpage : Special Parameters @ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed). -D -- "Don't use C; In my opinion, C is a library programming language not an app programming language." - Owen Taylor (GTK+ developer) GnuPG key : http://dman.ddts.net/~dman/public_key.gpg pgpMWm9eYHPSi.pgp Description: PGP signature