Sujet : Re: [ksh] Warning: pipe symbol within ${} should be quoted?
De : martijn (at) *nospam* inlv.demon.nl (Martijn Dekker)
Groupes : comp.unix.shellDate : 30. May 2025, 20:52:48
Autres entêtes
Message-ID : <m9ugkgFmj4sU1@mid.individual.net>
References : 1
User-Agent : Mozilla Thunderbird
Op 08-05-2025 om 00:00 schreef Janis Papanagnou:
With syntax-check ('ksh -n') I get a warning in Ksh for this expression
"${pipe#* | }"
concerning the pipe symbol. (Bash and Zsh don't complain.)
But bash and zsh don't offer linter functionality with -n at all, do they?
(2709)$ ksh -n -c '"${pipe#* | }"'
ksh: warning: line 1: | within ${} should be quoted
ksh -n currently produces the warning in this context for these characters:
& < > |
There is nothing in the POSIX shell grammar that suggests these should be quoted there. The string between # and } is a shell pattern, and those are not special characters in POSIX shell patterns.
While ksh does support extended shell pattern syntax in which & and | may be metacharacters, those characters are not special unless that extended shell pattern syntax is actually used (in which case you don't want to quote them if you want them to be metacharacters). And < and > are never special in patterns at all.
My conclusion is that this warning is unhelpful. I'll remove it.
By the way, a little test script shows that old ksh versions had some bugs here:
pipe="one | two"
echo "${pipe#* | }"
pipe="one & two"
echo "${pipe#* & }"
pipe="one < two"
echo "${pipe#* < }"
pipe="one > two"
echo "${pipe#* > }"
Output on ksh 93u+ 2012-08-01, the last "stable" AT&T release:
| two
one & two
two
two
Output on ksh 93u+m as of 2022-02-08 (as well as AT&T ksh as of 93v- 2012-08-24 beta):
two
two
two
two
I believe the latter is the correct output.
-- || modernish -- harness the shell|| https://github.com/modernish/modernish|||| KornShell lives!||
https://github.com/ksh93/ksh