rvmsudo confused by exported multiline bash functions #1094

tjensen opened this Issue Sep 6, 2012 · 0 comments


None yet
2 participants

tjensen commented Sep 6, 2012

If the environment includes an exported multiline bash function containing "RUBY" or "GEM", rvmsudo may report a syntax error in the "eval" command. I am using rvm 1.15.8 (stable).

To reproduce the syntax error, run the following commands:

$ foobar() { echo Start; if $MY_RUBY_HOME/bin/ruby -e 'puts "testing"'; then echo Success; else echo Failure; fi; echo done; }
$ export -f foobar
$ rvmsudo echo hello

The "rvmsudo" command will produce the following error:

/home/tjensen/.rvm/bin/rvmsudo: eval: line 46: syntax error near unexpected token `then'
/home/tjensen/.rvm/bin/rvmsudo: eval: line 46: `command sudo "${sudo_args[@]}" /usr/bin/env rvm_bin_path="/home/tjensen/.rvm/bin" rvm_verbose_flag="0" rvm_path="/home/tjensen/.rvm" rvm_debug_flag="0" rvm_prefix="/home/tjensen" PATH="/home/tjensen/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/tjensen/.rvm/bin" rvm_version="1.15.8 (stable)" if $MY_RUBY_HOME/bin/ruby -e 'puts "testing"'; then "$@"'

I think the following may be sufficient to filter out exported functions when invoking sudo:

eval command sudo \"\${sudo_args[@]}\" /usr/bin/env $(/usr/bin/env -0 | GREP_OPTIONS="" \grep -zv "=()" | GREP_OPTIONS="" \grep -zE '^rvm|^gemset|^http_|^PATH|^IRBRC|RUBY|GEM' | tr "\000" "\n" | sed 's/=\(.*\)$/="\1"/' ) \"\$@\"

@ghost ghost assigned mpapis Sep 6, 2012

@mpapis mpapis closed this in ac4ee19 Sep 12, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment