tilde expansion with a variable

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Lynn David Newton
Date:  
Subject: tilde expansion with a variable
ldn> I've known for years that one can't do tilde
ldn> expansion with a variable name, e.g.,


ldn> WHO=joeuser
ldn> cd ~$WHO


ldn> doesn't work, but I have never quite grokked
ldn> exactly why, or whether there is a workaround.


As usual, I found the answer moments after sending off
my question.

The solution is this:

eval cd \~$WHO

This in both bash and ksh.

The problem is because of the order of evaluation of
operators. ~ has higher precidence than $.

That little tidbit of knowledge is going into my facts
file.

--
Lynn David Newton
Phoenix, AZ