This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -a $HOME/.bashrc and -a ~/.bashrc produce different results


On 05/19/2011 02:54 PM, Lee Maschmeyer wrote:
> Hi all,
> 
> For most uses, $HOME and ~ produce identical results. For example, ls
> $HOME or ls ~ are the same. But the following script fails:
> 
> Presumably I'm doing something nefarious but I can't figure out what.

I can.  And it's not cygwin-specific.

> for i in "$HOME/.bashrc" "~/.bashrc" ; do

"$HOME" expands $HOME, but "~/.bashrc" does _not_ expand ~.  For
tilde-expansion to occur, it must be unquoted.

>    if [ -a "$i" ]; then

Use 'set -vx' to see what was really run.  The first iteration ran:

'[' '-a' '/home/blah/.bashrc' ']'

while the second ran:

'[' '-a' '~/.bashrc' ']'

> 
> As far as I can tell I've done everything right, but I can't believe
> I've discovered a bug! I think I _am_ the bug. :-)

Correct assumption, for once :)

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]