On 25 October 2012 13:50, Dan Douglas <[email protected]> wrote: > On Thursday, October 25, 2012 06:40:59 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 >> $ >> >> I think bash behavior is correct according to >> > http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06which >> says tilde expansion should be done before parameter expansion. > > And the workaround is pretty nasty... > > u=root; id -u "$u" >/dev/null 2>&1 && eval echo ~$u > > The beauty of the way Ksh does this is it still scans for unescaped/unquoted > tilde-prefixed words before parameter expansion. There's no chance of > ambiguity, and an unintentional tilde expansion is unlikely. > > $ u=\~root; print -r $u > ~root > > The tilde must lexically precede the $u and be unquoted in order to get tilde > expansion. I'm not so sure this even conflicts with POSIX requirements. > > In ksh93v there's now a syntax to get readlink functionality out of tilde > expansion. > > $ ( { echo ~{x}; } <<<'' {x}<&0 <&2 ) > /proc/32185/fd/13 > > This is an awesome feature... it would be a shame to require an eval here.
This isn't readlink support. It's a a smart solution to allow child processes to access the shell's inherited file descriptors. We already heavily rely on this feature, both for IPC and to shorten very long paths to speed processing up. Lionel _______________________________________________ ast-users mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-users
