简体   繁体   中英

How are $LOAD_PATH and $: different?

I needed to know what was in my Ruby load path, so I did this:

$ ruby -e "puts $LOAD_PATH"

It didn't print anything out, which I didn't expect. So I tried this:

$ ruby -e "puts $:"
/usr/local/lib/site_ruby/1.8
/usr/local/lib/site_ruby/1.8/i486-linux
/usr/local/lib/site_ruby/1.8/i386-linux
/usr/local/lib/site_ruby
/usr/lib/ruby/vendor_ruby/1.8
/usr/lib/ruby/vendor_ruby/1.8/i486-linux
/usr/lib/ruby/vendor_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i486-linux
/usr/lib/ruby/1.8/i386-linux
.

Why does the second one give me the expected output and the first one doesn't? Shouldn't they be the same? I just tried it in irb , and I got the results I expected.

This is my Ruby version, in case it makes a difference:

$ ruby --version
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]

They are not. Try running this command:

$ ruby -e 'puts $LOAD_PATH'

which doesn't make shell expand $LOAD_PATH due to use of ' instead of " .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM