On 10/25/2012 04:07 PM, Clark WANG wrote:
See following example:
$ cat foo.sh
u=root
echo ~$u
$ bash foo.sh # bash 4.2.37
~root
$ ksh foo.sh # ksh 93u+ 2012-08-01
/root
$
Anyone can explain/confirm what should be the correct behavior?
-Clark
http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions
quoting:
The order of expansions is: brace expansion, tilde expansion, parameter,
variable, and arithmetic expansion and command substitution (done in a
left-to-right fashion), word splitting, and filename expansion.
And posix is saying:
The order of word expansion shall be as follows:
1. Tilde expansion (see Section 2.6.1), parameter expansion (see Section
2.6.2, on page 2306),
command substitution (see Section 2.6.3, on page 2309), and
arithmetic expansion (see
Section 2.6.4, on page 2299).
So I will say, bash is doing it right. Firstly tries tilde expansion and
then parameter expansion.
RR