tilde expansion with a variable

Lynn David Newton plug-discuss@lists.plug.phoenix.az.us
Wed, 5 Feb 2003 09:07:02 -0700


  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