help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Expansion of unquoted special parameter $@ when used as the word for


From: Greg Wooledge
Subject: Re: Expansion of unquoted special parameter $@ when used as the word for a HERE STRING
Date: Tue, 5 Nov 2019 16:23:14 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Tue, Nov 05, 2019 at 10:30:39AM -1000, Robin A. Meade wrote:
> Consider:
> 
> set a 'b   c'
> cat <<< $@;
> 
> The output is:
> 
> a b c
> 
> I expected the 3 spaces between b and c to be preserved.

wooledg:~$ set -- a 'b   c'
wooledg:~$ cat <<< "$*"
a b   c
wooledg:~$ cat <<< "$@"
a b   c
wooledg:~$ cat <<< $@
a b c

Technically only "$*" is correct here.  That expands to a single word.
"$@" expands to a list of words, and it doesn't really make sense to
use a here-string with a list of strings.

Unquoted $* and $@ are just plain wrong, and you shouldn't use them.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]