Dir.chdir '~'

Discussion in 'Ruby' started by Joel VanderWerf, Jan 3, 2004.

  1. Does anyone know why this happens?

    $ irb
    irb(main):001:0> Dir.chdir '~'
    => 0
    irb(main):002:0> Dir.chdir '~'
    Errno::ENOENT: No such file or directory - ~
    from (irb):2:in `chdir'
    from (irb):2
    $ ruby -v
    ruby 1.8.1 (2003-12-25) [i686-linux]
     
    Joel VanderWerf, Jan 3, 2004
    #1
    1. Advertising

  2. Tim Heaney wrote:
    > Joel VanderWerf <> writes:
    >
    >
    >>Does anyone know why this happens?
    >>
    >>$ irb
    >>irb(main):001:0> Dir.chdir '~'
    >>=> 0
    >>irb(main):002:0> Dir.chdir '~'
    >>Errno::ENOENT: No such file or directory - ~
    >> from (irb):2:in `chdir'
    >> from (irb):2
    >>$ ruby -v
    >>ruby 1.8.1 (2003-12-25) [i686-linux]

    >
    >
    > You must be starting out in a directory with a ~ subdirectory that
    > does not itself have a ~ subdirectory. Thus the first time you change
    > to directory ~ it succeeds, but the second time it fails.


    Yep, that was it. Thanks!
     
    Joel VanderWerf, Jan 3, 2004
    #2
    1. Advertising

  3. Mark J. Reed wrote:
    > On Fri, Jan 02, 2004 at 09:22:02PM -0500, Tim Heaney wrote:
    >
    >>Joel VanderWerf <> writes:
    >>
    >>
    >>>Does anyone know why this happens?
    >>>
    >>>$ irb
    >>>irb(main):001:0> Dir.chdir '~'
    >>>=> 0
    >>>irb(main):002:0> Dir.chdir '~'
    >>>Errno::ENOENT: No such file or directory - ~
    >>> from (irb):2:in `chdir'
    >>> from (irb):2
    >>>$ ruby -v
    >>>ruby 1.8.1 (2003-12-25) [i686-linux]

    >>
    >>You must be starting out in a directory with a ~ subdirectory that
    >>does not itself have a ~ subdirectory. Thus the first time you change
    >>to directory ~ it succeeds, but the second time it fails.

    >
    >
    > More to the point, I think is that Ruby doesn't expand ~ the way
    > the UNIX shells do. What you probably want is Dir.chdir(ENV['HOME']).


    Ok. I guess I have to expand_path if I want that behavior.

    irb(main):001:0> File.expand_path '~'
    => "/home/vjoel"

    Thanks!
     
    Joel VanderWerf, Jan 3, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    450
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. Tom McDavid
    Replies:
    0
    Views:
    507
    Tom McDavid
    May 13, 2004
  3. Tim Kynerd
    Replies:
    12
    Views:
    284
    Yukihiro Matsumoto
    Nov 28, 2003
  4. Père Noël

    Dir.chdir("..") versus `cd ..`

    Père Noël, Dec 11, 2006, in forum: Ruby
    Replies:
    6
    Views:
    139
    Père Noël
    Dec 11, 2006
  5. vulpes
    Replies:
    3
    Views:
    143
    vulpes
    Mar 21, 2007
Loading...

Share This Page