Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm running a script (in tmuxinator) that tries to source another script (rvm). rvm explicitly does not allow sourcing from sh. I didn't think that would be a problem, because the shebang in the tmuxinator script is

#!/bin/bash

but when I insert the code suggested by the rvm people to source rvm from a script,

if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  source "$HOME/.rvm/scripts/rvm"
fi

-I get

sh: 6: [[: not found

Why is sh being used as the interpreter there? I've also used #!/usr/bin/zsh (which is the value of $SHELL in the interactive shell from which I called the script) and #!/usr/bin/env zsh, but they give the same complaint.

share|improve this question
    
On the face of what you're saying, it should work, so you must have left something out. Post or link to the full script that you've added this snippet to, and tell us exactly how it's invoked. –  Gilles Apr 12 '13 at 21:56
    
I've actually pared the script down to just what I posted and get the same result. The script is being called by Ruby, with the Kernel#exec method, but I can't find any reason why that should be forcing the use of sh. –  bgates Apr 13 '13 at 4:06
    
...until I looked at the documentation for Kernel#exec. "The standard shell means always “/bin/sh” on Unix-like systems". Well. –  bgates Apr 13 '13 at 4:22

2 Answers 2

Does RVM operate in a /bin/sh context? This is likely the reason you're encountering this difficulty; the source'd script inherits the parent's interpreter. See: http://ss64.com/bash/source.html

. (source or dot operator)

Read and execute commands from the filename argument in the current shell context.

(emphasis mine)

share|improve this answer
    
I'm not reaching the source command, though. I hit the double bracket operator and sh complains about it because it's a bashism. –  bgates Apr 13 '13 at 4:17
    
What's the value of ls -ld /bin/bash ? –  laebshade Apr 25 '13 at 15:03
    
-rwxr-xr-x 1 root root 959168 Sep 19 2012 /bin/bash though as I said below the real problem was Ruby's exec command forcing the use of /bin/sh unless explicitly told to do otherwise. Thanks for the reminder about this question; I forgot to mark the solution I found as answered. –  bgates Apr 26 '13 at 21:32
up vote 0 down vote accepted

It looks like the problem was the script was called from Ruby with

exec(script)

and exec always operates in the context of /bin/sh, the shebang line in the called script apparently notwithstanding.

Changing to

exec('/bin/bash', '-c', script)

works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.