Ist it possible to kind of define a default shell which will be used
for Kernel::system? I often need to invoke from my Ruby scripts
external commands, involving redirection and globbing, for example
(bash syntax)
foo [a-z]* 2>&-
bar <<<baz
etc. Since these syntactic elements are shell specific, I need to
specify the shell somehow, for example:
system("bash --norc -c 'foo [a-z]* 2>&-'")
system("bash --norc -c 'bar <<<baz'")
which is a bit cumbersome. Of course one obvious solution would be
to define a new function:
def bash(cmd)
system("bash --norc -c '"+cmd+"'")
end
And use instead
bash('foo [a-z]* 2>&-')
bash('bar <<<baz')
But this solution has two drawbacks:
First one has to pay special attention that the shell command itself
should no contain single quotes. For example, it is all too tempting
to write a call
bash("my_command 'one argument'")
which looks correct at first sight, but will have a different
effect than
bash('my_command "one argument"')
due to the interference between Ruby- and bash quoting.
Another drawback of this solution is that one has to include the
definition of the “bash” function with each Ruby script.
So I wonder whether there is may be a simple, builtin solution
for this problem - say, a way to specify the “default shell” used
for system().
Ronald