Re: `printf -v foo ""` does not set foo=
Linda Walsh writes: > I have a feeling this would be hard to fix, since how can printf > tell the difference between > printf -v foo "" > and > printf -v foo > ?? The latter has $# -eq 2. Andreas. -- Andreas Schwab, SUSE Labs, sch...@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."
Aw: Re: `printf -v foo ""` does not set foo=
Thats one of the reasons I suggested the following syntax printf -v test "%s" "" It doesn't have this problem it also saves other problems as well. of if you want to expand back slashes etc. printf -v test "%b" "" Gesendet: Montag, 17. Juni 2013 um 08:33 Uhr Von: "Linda Walsh" An: bug-bash@gnu.org Betreff: Re: `printf -v foo ""` does not set foo= Mike Frysinger wrote: > simple test code: > unset foo > printf -v foo "" > echo ${foo+set} > > that does not display "set". seems to have been this way since the feature > was added in bash-3.1. > -mike Indeed: > set -u > unset foo > printf -v foo "" > echo $foo bash: foo: unbound variable > foo="" > echo $foo I have a feeling this would be hard to fix, since how can printf tell the difference between printf -v foo "" and printf -v foo ?? (with nothing after it?) it seems the semantic parser would have already removed the quotes by the time the args are passed to printf, even this: > set -u > printf -v foo "$(echo "$'\000'")" > echo $foo still leaves foo gutless: without content (even if were null)
Re: currently doable? Indirect notation used w/a hash
On Sat, Jun 15, 2013 at 12:36:22PM -0700, Linda Walsh wrote: > John Kearney wrote: > >There is also a backdoor approach that I don't really advise. > >val="${ArrayName}[Index]" > >echo "${!val}" > - > Don't advise? Any particular reason? or stylistic? I'd shared this advice ("don't use it"), because I cannot for the life of me tell whether this is a bug or a feature. As near as I can tell, it is an unforeseen consequence of the parser implementation, not documented anywhere. As such, I would not rely on it to continue working in future Bash releases. P.S. you meant printf -v, not -V.
Aw: Re: currently doable? Indirect notation used w/a hash
Like I said its a back door aproach, it circumvents the parser. which doesn't allow this syntax ${${Name}[1]} I didn't actually find this myself it was reproted on this list a long time ago. I do remember Chet saying he wouldn't break it. But other than that I can't remember the discussion all that well. As always with this topic it was a pretty lively debate. Yhea its a constant fight getting my email clients to stop capitialising various things in code. Gesendet: Montag, 17. Juni 2013 um 13:57 Uhr Von: "Greg Wooledge" An: "Linda Walsh" Cc: "John Kearney" , bug-bash Betreff: Re: currently doable? Indirect notation used w/a hash On Sat, Jun 15, 2013 at 12:36:22PM -0700, Linda Walsh wrote: > John Kearney wrote: > >There is also a backdoor approach that I don't really advise. > >val="${ArrayName}[Index]" > >echo "${!val}" > - > Don't advise? Any particular reason? or stylistic? I'd shared this advice ("don't use it"), because I cannot for the life of me tell whether this is a bug or a feature. As near as I can tell, it is an unforeseen consequence of the parser implementation, not documented anywhere. As such, I would not rely on it to continue working in future Bash releases. P.S. you meant printf -v, not -V.