chruby
chruby copied to clipboard
Chruby exec dash
if chruby-exec is executed and SHELL is somehow equal to dash, use bash or zsh instead.
What's the purpose of these changes? I assume one can still execute the sub-command under dash, so long as chruby exports PATH
, GEM_HOME
, GEM_PATH
, etc.
chruby-exec fails under dash because dash fails in sourcing chruby.sh. Here is the output with a set -x
in chruby-exec.
# cat /etc/debian_version
7.7
# echo $SHELL
/bin/sh
# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 1 2012 /bin/sh -> dash
# chruby-exec ruby-2.1.2 -- ruby -v
+ source /usr/bin/../share/chruby/chruby.sh
++ CHRUBY_VERSION=0.3.9
++ RUBIES=()
++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
++ [[ -d /opt/rubies ]]
+++ ls -A /opt/rubies
++ [[ -n ruby-2.1.2
ruby-2.1.5 ]]
++ RUBIES+=("$dir"/*)
++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
++ [[ -d /root/.rubies ]]
++ unset dir
+ case "$1" in
+ (( 4 == 0 ))
+ argv=()
+ for arg in '"$@"'
+ shift
+ [[ ruby-2.1.2 == \-\- ]]
+ argv+=($arg)
+ for arg in '"$@"'
+ shift
+ [[ -- == \-\- ]]
+ break
+ (( 2 == 0 ))
++ printf '%q ' ruby-2.1.2
++ printf '%q ' ruby -v
+ command='chruby ruby-2.1.2 && ruby -v '
+ [[ -t 0 ]]
+ exec /bin/sh -i -l -c 'chruby ruby-2.1.2 && ruby -v '
/bin/sh: 1: chruby: not found
#
Ah I see. The purpose of running chruby within $SHELL
is to support any shell specific configuration the user setup. You could export SHELL
to ensure chruby-exec
invokes bash instead of dash. We could also add a check for dash and error out?
In my use case, the chruby-exec is fired off as a system call from within a ruby script (god) which uses /bin/sh. I don't have any specific user configuration and I don't want to error out. My thinking was that in a case where chruby-exec was run under dash, it would just use a shell instead that works (bash or zsh).
What is the default shell of the user that runs this script?