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.)
(2709)$ ksh -n -c '"${pipe#* | }"'
ksh: warning: line 1: | within ${} should be quoted
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.
On 30.05.2025 21:52, Martijn Dekker wrote:
Op 08-05-2025 om 00:00 schreef Janis Papanagnou:
I don't know what they internally do when '-n' is provided, but theWith syntax-check ('ksh -n') I get a warning in Ksh for this expressionBut bash and zsh don't offer linter functionality with -n at all, do they?
"${pipe#* | }"
concerning the pipe symbol. (Bash and Zsh don't complain.)
man page (e.g. "man bash") says for the 'set' command (-n/-o noexec)
-n Read commands but do not execute them. This may be used
to check a shell script for syntax errors. This is ignored
by interactive shells.
which appears to be the same as what's written in the Ksh man page
(and in POSIX), and I suppose a similar thing valid for Zsh.
On 30.05.2025 21:52, Martijn Dekker wrote:
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?
I don't know what they internally do when '-n' is provided, but the
man page (e.g. "man bash") says for the 'set' command (-n/-o noexec)
-n Read commands but do not execute them. This may be used
to check a shell script for syntax errors. This is ignored
by interactive shells.
which appears to be the same as what's written in the Ksh man page
(and in POSIX), and I suppose a similar thing valid for Zsh.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 24:08:53 |
| Calls: | 810 |
| Calls today: | 1 |
| Files: | 1,287 |
| D/L today: |
12 files (21,036K bytes) |
| Messages: | 195,978 |