N
Noah Easterly
What subshell does ` (backquote) use to run commands?
Noah Easterly said:What subshell does ` (backquote) use to run commands?
Noah said:I don't think it's using the $SHELL variable to choose which shell to
use (and I don't trust all the shells to set $SHELL)
As an example:
so here's a command that I get different responses on, depending on
which shell it's run in
sh-2.05b$ ls **/*.rb | wc -l
1
sh-2.05b$ zsh -c "ls **/*.rb | wc -l"
12
And in ruby backticks, I get the sh response
sh-2.05b$ ruby -e "puts %x{ls **/*.rb | wc -l}"
1
I don't think it's using the $SHELL variable to choose which shell to
use (and I don't trust all the shells to set $SHELL)
As an example:
so here's a command that I get different responses on, depending on
which shell it's run in
sh-2.05b$ ls **/*.rb | wc -l
1
sh-2.05b$ zsh -c "ls **/*.rb | wc -l"
12
And in ruby backticks, I get the sh response
sh-2.05b$ ruby -e "puts %x{ls **/*.rb | wc -l}"
1
even when the $SHELL is set otherwise
sh-2.05b$ export SHELL=/bin/zsh
sh-2.05b$ echo $SHELL
/bin/zsh
sh-2.05b$ ruby -e "puts %x{echo $SHELL}"
/bin/zsh
sh-2.05b$ ruby -e "puts %x{ls **/*.rb | wc -l}"
1
or if the ruby script is run by a different shell
zsh: echo $SHELL
/bin/zsh
zsh: ruby -e "puts %x{echo $SHELL}"
/bin/zsh
zsh: ruby -e "puts %x{ls **/*.rb | wc -l}"
1
So my question remains, how is ruby choosing which shell to use for
backtick commands? (since in this case it really doesn't seem like it's
checking $SHELL at all).
I know I can force a choice of shell from within the backtick (ruby -e
'puts %x{/bin/sh -c "ls **/*.rb | wc -l"}'), but I want to know where
ruby's getting its choice of shell from.
irb(main):001:0> `echo $SHELL`
=> "/bin/bash\n"YMMV, depending on platform and version.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.