shell - "source" in ruby subshells -


i need run shell command ruby application. i'm using system() applies backticks.

when running command, need load shell script first sets things try this:

system("source my_script.sh && my_command") 

on mac laptop works intended on ubuntu server get:

sh: 1: source: not found 

i wondering "sh" in there since shell should bash, tried this:

system("echo $shell && source my_script.sh && my_command") 

which gives me:

/bin/bash sh: 1: source: not found 

so, using right shell reason, source not work.

why? , can it?

update sergio tulentsev pointed out, ruby not use shell set in $shell.

this gave me actual shell ruby using:

system("ps -p $$ | tail -1 | awk '{print $nf}'") sh  => true 

so, it's using sh. can somehow force use bash?

you need try adding ./ in front of file want source, should work if subshell bash (check $shell).

irb(main):003:0> system("source ./test.sh && echo $test && cat test.sh") test export test=test => true 

if $shell sh, need . ./test.sh instead of source ./test.sh, source keyword bash only.

or can make sure using bash, doing:

irb(main):007:0> system("/bin/bash -c 'source ./test.sh && echo $test && cat test.sh'") test export test=test => true 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -