[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question on differences on quoted $* (Was: Re: Question on $@ vs $@$
From: |
Steffen Nurpmeso |
Subject: |
Re: Question on differences on quoted $* (Was: Re: Question on $@ vs $@$@) |
Date: |
Sun, 25 Aug 2024 03:27:24 +0200 |
User-agent: |
s-nail v14.9.25-599-g5c75a327b2 |
Emanuele Torre wrote in
<ZskqVqdZSXMHns1k@ntoo>:
|On Sat, Aug 24, 2024 at 02:15:48AM +0200, Steffen Nurpmeso wrote:
|> Sorry but i really have to come again, i do not understand what is
|> going on, and *i* think shell is at fault.
|
|No. It is working correctly.
|
|> This:
|>
|> a() {
|> echo $#,1=$1,2=$2,"$*",$*,
|
|This $1 is unquoted, it will be split. You need to use "$1" if you don't
|want it to split.
Ah. Of course. Stupid me.
Yes, splitting was not yet done at all except for unquoted $*,
when i set that free i am en par. Yay. (Though i have three
dozens of tests which now fail, and have to be adjusted
accordingly.)
...
|> a:b:ca b c a b c
|> -6,1=a b ca,2=b,a:b:ca:b:c:a:b:c,a b ca b c a b c,
|> +6,1=a:b:ca,2=b,a:b:ca:b:c:a:b:c,a b ca b c a b c,
|>
|> Why does bash, when preparing the first argument to the function
|> a(), ie, when word-splitting "$*", not generate "a:b:c" as it very
|> well does when it creates the output for echo(1)?
|> Where is the difference in between the '"$*"$* $*' of the one
|> argument, and the '"$*"$* $*' of the other?
|
|Even though you are passing "a:b:ca" as $1, you are running echo $1 to
|print it while IFS is still set to ":" so $1 will be split to "a" "b"
|"ca".
Thanks again.
...
|o/
| emanuele6
--End of <ZskqVqdZSXMHns1k@ntoo>
Robert Elz wrote in
<26236.1724475172@jacaranda.noi.kre.to>:
| Date: Sat, 24 Aug 2024 02:33:26 +0200
| From: Emanuele Torre <torreemanuele6@gmail.com>
| Message-ID: <ZskqVqdZSXMHns1k@ntoo>
|
|| No. It is working correctly.
|
|It is indeed.
|
|| This $1 is unquoted, it will be split. You need to use "$1" if you don't
|| want it to split.
|
|Alternatively, make a() be
|
| a()
| {
| local IFS=
| echo $#,1=$1,2=$2,"$*",$*,
|}
|
|then you'll get to see what the actual args are, as no splitting
|will happen. Of course, the expansion of "$*" will be different
|in this case (but the the unquoted version only by not having
|word splitting performed on the fields it produces).
No no, the function is exactly as it should be; .. i will however
add additional quoted forms of "$1" etc to the output.
|You could also see what happened in the original case if you ran
|the test with -x set (this segment from the final input line):
|
|+ IFS=:
|+ echo a:b:ca b c a b c
|a:b:ca b c a b c
|+ a a:b:ca b c a b c
|+ echo 6,1=a b ca,2=b,a:b:ca:b:c:a:b:c,a b ca b c a b c,
|6,1=a b ca,2=b,a:b:ca:b:c:a:b:c,a b ca b c a b c,
|+ unset IFS
|
|You can see there that the args passed to 'a' and the args passed
|to the first "echo" (outside 'a') are identical.
That is a really good idea indeed, to be remembered.
|
|kre
--End of <26236.1724475172@jacaranda.noi.kre.to>
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)