Skip to content

Conversation

@grimm26
Copy link

@grimm26 grimm26 commented Dec 9, 2014

if chruby-exec is executed and SHELL is somehow equal to dash, use bash or zsh instead.

@postmodern
Copy link
Owner

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.

@grimm26
Copy link
Author

grimm26 commented Dec 10, 2014

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
#

@postmodern
Copy link
Owner

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?

@grimm26
Copy link
Author

grimm26 commented Dec 12, 2014

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).

@postmodern
Copy link
Owner

What is the default shell of the user that runs this script?

@grimm26 grimm26 closed this by deleting the head repository Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants