Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is the difference between "./command" and "bash command"

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:
./scriptname.sh


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?
by

1 Answer

Bharatgxwzm
There is a BIG difference.

Lets take the following script called testscript (configured to use /bin/ksh as you see in the hashbang):
#!/bin/ksh
#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

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.

Login / Signup to Answer the Question.