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]
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 vjoel@PATH.Berkeley.EDU 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.
$ mkdir ~
$ irb
irb(main):001:0> Dir.chdir ‘~’
=> 0
irb(main):002:0> Dir.pwd
=> “/home/tim/ruby/~”
irb(main):003:0> Dir.chdir ‘~’
Errno::ENOENT: No such file or directory - ~
from (irb):3:in `chdir’
from (irb):3
In Ruby, you can use use ENV[‘HOME’], rather than ~, to refer to your
home directory, if that’s what you intended. However, Dir.chdir
defaults to your home directory, so you don’t actually need that in
this case.
$ irb
irb(main):001:0> Dir.pwd
=> “/home/tim/ruby”
irb(main):002:0> Dir.chdir
=> 0
irb(main):003:0> Dir.pwd
=> “/home/tim”
I hope this helps,
Tim
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’]).
-Mark
On Fri, Jan 02, 2004 at 09:22:02PM -0500, Tim Heaney wrote:
Joel VanderWerf vjoel@PATH.Berkeley.EDU 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.
Tim Heaney wrote:
Joel VanderWerf vjoel@PATH.Berkeley.EDU 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!
Mark J. Reed wrote:
On Fri, Jan 02, 2004 at 09:22:02PM -0500, Tim Heaney wrote:
Joel VanderWerf vjoel@PATH.Berkeley.EDU 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!