Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost under Linux, invoking bootstrap
From: Anthony Foiani (tkil_at_[hidden])
Date: 2013-05-06 01:13:12


Edward Diener <eldiener_at_[hidden]> writes:

> Thanks ! I found that out also. Because I am mostly a Windows
> programmer I thought that the bash shell replaces '~' with the
> user's home directory but that's obviously wrong. I am still
> learning about the bash shell and still making mistakes.

It's even weirder than that, and it's weirder than I thought (and I've
been on Unix-type systems for ... 25+ years at this point). I thought
that you were bitten by a rule that allowed tilde expansion only at
the beginning of a non-quoted word.

That is, I thought this would work, and it does:

  $ echo ~
  /home/tkil

But I thought this would fail, and it still worked!

  $ echo foo=~
  foo=/home/tkil

This fails as I expected:

  $ echo -e --foo=~
  --foo=~

It turns out that there is a "maybe bug" in bash, where it tries to do
tilde expansion when it thinks that it is doing an assignment. That
feature makes it possible to say:

  my_bin_dir=~/bin

But this logic is also kicking in for the second case above. It does
not trigger on the third case, because "--foo" is not a valid variable
name.

Some more good reading here, including a situation similar to yours,
where the author admits: "I don't know yet, if this is a bug or
intended."

  http://wiki.bash-hackers.org/syntax/expansion/tilde

As others have said, using $HOME is a good solution for your own home
directory. (To a first approximation, you only need the ${HOME} form
if you need to tell bash where your variable name ends and other text
begins.)

Home directories for other users can be obtained via "eval", or by
using the bash variable-assignment trick above:

  $ echo --foo=~kevin/bin
  --foo=~kevin/bin

  $ kevins_bin_dir=~kevin/bin

  $ echo --foo=$kevins_bin_dir
  --foo=/home/kevin/bin

You can also use the $(...) shortcut for "execute and give me the
output":

  $ echo --foo=$(echo ~kevin/bin)
  --foo=/home/kevin/bin

Which is, itself, a newer / saner / easier-to-read (IMHO) version of
the venerable backticks:

  $ echo --foo=`echo ~kevin/bin`
  --foo=/home/kevin/bin

It's funny that you ran into this. As someone who uses Unix-y systems
most of the time, I find that doing command-line work on Windows is an
epic pain. "What do you mean, the shell doesn't expand '*' for
you???"

Different strokes. :)

Happy hacking!

Best regards,
Anthony Foiani


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net