简体   繁体   中英

environment variable expansion in first line of shell script

My ruby shell scripts specify the ruby interpreter in the first line of the script as:

#!/Users/me/.rvm/rubies/ruby-1.9.3-p194/bin/ruby

The problem is that when I upgrade to a new ruby version, I have to edit all the script files to update the interpreter. There is an environment variable available, $MY_RUBY_HOME, that expands to the current path (minus the /bin/ruby part). However, all my attempts to use:

#!{$MY_RUBY_HOME}/bin/ruby
#!${MY_RUBY_HOME}/bin/ruby
etc

fail ("bad interpreter: No such file or directory"). I suspect environment expansion isn't done on the first line, so I may just be out of luck. I would be interested if anybody has been able to use environment variable expansion on the program definition line in a shell script.

Put ${MY_RUBY_HOME}/bin in your $PATH and use #!/usr/bin/env ruby . See here .

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