tilde expansion with a variable

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: G.D.Thurman
Date:  
Subject: tilde expansion with a variable
On Wed, 5 Feb 2003, Lynn David Newton wrote:

> I've known for years that one can't do tilde expansion
> with a variable name, e.g.,
>
> WHO=joeuser
> cd ~$WHO
>
> doesn't work, but I have never quite grokked exactly
> why, or whether there is a workaround.
>


$ is my prompt. Only executed with bash.
The following command-lines were tried.

$ echo $SHELL
/bin/bash

$ WHO=root

$ eval cd ~$WHO
bash: cd: /root: Permission denied

Potential solution?

>From your code...


    cp $files ~$u


switch to

eval cp $files ~$u

Thurman