Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Should ~$user be tilde expanded?

4 views
Skip to first unread message

Clark WANG

unread,
Oct 25, 2012, 10:07:10 AM10/25/12
to bash.bug list
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

Roman Rakus

unread,
Oct 25, 2012, 10:18:11 AM10/25/12
to bug-...@gnu.org
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

0 new messages