Dir.chdir '~'

  • Thread starter Joel VanderWerf
  • Start date
J

Joel VanderWerf

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]
 
J

Joel VanderWerf

Tim said:
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!
 
J

Joel VanderWerf

Mark said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top