I have simple bash script file, it contains only one line:

rvm gemset use --create 2.0.0@PRJ_NAME

If I run this script with:


I get a well-known error message from RVM

RVM is not a function, select.....

but if I run the script with

bash scriptname.sh

everything is ok.

Can someone explain the difference to me?

  • 1
    Can you show us the contents of your .bashrc that set rvm environment variables? – Mark Plotnick May 27 '16 at 13:09
  • Maybe you should add #!/bin/bash in the beginning of your script! – coffeMug May 27 '16 at 14:19

There is a BIG difference.

Lets take the following script called testscript (configured to use /bin/ksh as you see in the hashbang):

#im testscript
cd /proc/$$
file exe

First lets execute it with ./:

$ ./testscript
exe: symbolic link to /bin/ksh93

Now calling bash:

$ bash testscript
exe: symbolic link to /bin/bash

Do you see the difference? The interpreter used by the script changed in the second command, so if the script depends in some ksh specific code it will be broken, and in other way if the scripts depends on bash specific code, then will broke it with the first command.

Other test you can do is to echo $PATH in the two different cases of execution.

  • Thanks for your answer @luciano-andress-martini but my question is slightly different. On my script I do not have any hashbang, is just one pure line. In this case the interpreter is not the difference. It must be something else. Something about subshell maybe? – Ignazio Calò May 27 '16 at 15:30
  • So maybe is that your problem, when you not use hashbang, your current command shell will be used instead of bash (specially if bash is not the default), type ps -A | grep $$ to see what you're using and when you use bash you corrected the problem, but if your believe that bash is really the default shell in your console, consider using hashbang because your console bash can have some unexpected environment for programming. – Luciano Andress Martini May 27 '16 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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