tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: sh(1) vs. ksh(1)
On Thu, 23 Oct 2008, Hauke Fath wrote:
> Apparently, with ksh(1), the expression
>
> configfsf_sub="`echo \"$0\" | sed 's/config.sub$/configfsf.sub/'`"
>
> ends up with the filename double-quoted in configfsf_sub.
I am not sure that the meaning of <backslash><doublequote> inside
backquotes inside double quotes is well defined. The NetBSD ksh(1) man
page says that it behaves differently depending on whether or not pOSIX
mode is in effect. See these extracts from the ksh(1) man page:
Quoting
[...]
Note: see POSIX Mode below for a special rule regarding sequences of
the form "...`...\"...`..".
POSIX Mode
[...]
The following is a list of things that are affected by the state of the
posix option:
o \" inside double quoted `..` command substitutions: in posix
mode, the \" is interpreted when the command is interpreted; in
non-posix mode, the backslash is stripped before the command
substitution is interpreted. For example, echo "`echo \"hi\"`"
produces `"hi"' in posix mode, `hi' in non-posix mode. To avoid
problems, use the $(...) form of command substitution.
Also try this under ksh:
$ set -o posix
$ echo "`echo \"hi\"`"
"hi"
$ set +o posix
$ echo "`echo \"hi\"`"
hi
The sensible interpretation (according to me) is the one that the
ksh(1) man page describes under non-posix mode. This is also the
interpretation used by bash and NetBSD /bin/sh.
I am unable to find any support in the SUSv3 chapter on shell syntax
<http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html>
for the interpretation that the ksh(1) man page calls posix mode,
but I do have a vague memory that SUSv2 might have been different.
I recommend that `...` substitutions should be replaced with $(...)
substitutions, which are easier to use and more clearly defined.
--apb (Alan Barrett)
Home |
Main Index |
Thread Index |
Old Index