Robert Klemme
8/12/2008 7:25:00 AM
On 12 Aug., 01:06, Thomas Luedeke <thomas.lued...@areva.com> wrote:
> Fred Phillips wrote:
> > On Tue Aug 12 06:46:26 2008, Thomas Luedeke wrote:
> >> However, if I try to change to that directory with a command such as
> >> Dir.chdir(" #{ENV['TMPDIR']} " ), I always get errors like this:
>
> > You don’t need the quotes, you can just do:
>
> > Dir.chdir(ENV['TMPDIR'])
>
> Whew - that did it. Thanks so much - that is a serious load off my
> back.
>
> Just for my newbie education, what was going wrong with what I was
> doing? What was Ruby thinking I was asking for??
You made things more complicated than necessary - probably because of
a shell programming background. In a shell it is a good idea to
enclose every variable expansion in double quotes because this will
prevent issues with whitespace in variable values. Ruby works quite
differently and the expression ENV['TMPDIR'] yields a single string -
even if there are spaces in $TMPDIR.
But since you choose to employ string interpolation, the result of the
expression in #{} was incorporated into the string, which happened to
have whitespace at the front and rear. Thus the resulting string also
had whitespace at the front and read and that path does not exist on
your filesystem. You can easily see it by doing
ruby -e 'p " #{ENV['TMPDIR']} "'
HTH
Kind regards
robert