[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Reverse redirection / assignment order
From: |
Dan Douglas |
Subject: |
Reverse redirection / assignment order |
Date: |
Wed, 09 Jan 2013 13:00:52 -0600 |
User-agent: |
KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; ) |
When expanding simple commands, steps 3 and 4 are reversed unconditionally for
all command types and number of words expanded, even in POSIX mode.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01
The exceptions allowed by POSIX appear to only apply to ksh93. Other shells
always use the POSIX order, except Bash, which never uses the POSIX order,
though the manpage description is the same as POSIX.
#!/usr/bin/env bash
# 1) no command expanded, 2) special builtin, 3) regular builtin.
tst() {
"$sh" -c 'x=$(printf 2 >&2) ${1+"$1"} <&0$(printf 1 >&2)' _ "$@"
} 2>&1
for sh in {,{b,d}a,po,{,m}k,z}sh bb; do
printf '%-4s: %s %s %s\n' "$sh" "$(tst)" "$(tst :)" "$(tst true)"
done
Out:
sh : 21 21 21 # bash posix mode
bash: 21 21 21 # normal mode
ksh : 21 21 12 # ksh93 is the other oddball shell
dash: 12 12 12 # ...
... # Everything else same as dash
I don't know why this order was chosen or what the advantages to one over the
other might be.
--
Dan Douglas
signature.asc
Description: This is a digitally signed message part.
- Reverse redirection / assignment order,
Dan Douglas <=