Problem when trying to run shell script : No such file or directory
Sebastian Wright
I'm trying to run the following command on bash:
./home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvmwhich is giving me a
bash: ./home/abcdef/Desktop/jikesrvm/dist/production_x86_64-linux/rvm: No such file or directoryrvm is a bash file, and it does run ok when I attempt to run it from its own folder (production_x86_64-linux). It works also fine if I attempt to run it when opening the terminal in its parent folder, for instance, or even its parent-parent folder.
I've run it over with dos2unix just in case and I've also checked its executing permissions, which seem to be fine.
What am I missing here?
14 Answers
you can run a bash script by using the following command
bash <location of the script file>in your case
bash /home/abcdef/Desktop/jikesrvm/dist/production_x86_64-linux/rvmit will work
what basically the . means is your current directory location.
if you are under your <user> folder then try doing this
./Desktop/jikesrvm/dist/production_x86_64-linux/rvmit will work but first you should make the file executable using the following command
chmod +x ~/Desktop/jikesrvm/dist/production_x86_64-linux/rvm 4 While you are trying:
./home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvmshell will always treat . in front of a path as current directory and hence the path will always be a relative path. So, shell is trying to find an executable file in the location:
$PWD/home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvmwhich is wrong as you can see. You would run a executable script that is the current directory as ./script.sh.
You can actually simply run the executable by using the absolute path (given the script is executable):
/home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvmOr as ~ is expaneded by shell as $HOME:
~/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvmOr even just the name of the script if the directory containing the script is in the PATH environment variable.
Now if your script is Not executable, you can run it too without making it an executable by telling the shell which program will handle the script i.e. giving the script as an argument to bash (shell):
bash /home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm When you use ./ to execute a file, it will look in the current folder (.) for a folder named home instead of starting from the root (/) directory.
Using the bash command explicitly like in bolzano's answer starts from the root directory instead of the one you're in.
To use the command without bash you could enter
/home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvmor
Desktop/jikesrvm/dist/prototype_x86_64-linux/rvmfrom your home directory assuming it is marked executable.
In addition to the other answers
What you tried was almost fine... But you forgot the extension .sh
- In your case./home/abcdef/Desktop/jikesrvm/dist/production_x86_64-linux/rvm.sh
- orcd /home/abcdef/Desktop/jikesrvm/dist/production_x86_64-linux./rvm.sh