I have a shell script named remote_execution.sh. Is it possible that I just type remote_execution in any of the folders and the execution starts, just like gcc, vi or any such command does?
Thanks in advance.
I have a shell script named remote_execution.sh. Is it possible that I just type remote_execution in any of the folders and the execution starts, just like gcc, vi or any such command does?
Thanks in advance.
The following four steps should allow you to run remote_execution from anywhere in your filesystem:
remote_execution, removing the .sh extensionAdd a "shebang" line to the top of the file
#!/bin/bash
Modify the permissions of the file so it is executable (see man chmod)
chmod u+x remote_execution
Move the file into a directory in your PATH so it "works in any folder". At a guess:
mv remote_execution /usr/local/bin
sudo mv remote_execution /usr/local/bin to write to /usr/local/bin?You could put that script in any folder depicted by $PATH
$ echo $PATH
[andreas@nyert test]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/andreas/bin
rename your script to remote_execution and put #!/bin/sh in the first line. Also chmod it to make sure it's executable
$ chmod 755 remote_execution
Each file has it's own permission bits. You have to modify the permissions of the file so it is executable. So use command -
chmod +x remote_execution
Hoping you have added "shebang" line to the top of the file
#!/bin/bash
If you call the script with an explicit interpreter, like
bash remote_execution.sh
/bin/bash remote_execution.sh
dash remote_execution.sh
sh remote_execution.sh
your choosen interpreter is used, no matter what the shebang says, which is just a comment. Otherwise the kernel looks for the shebang and starts the program with the therein specified interpreter. If Shebang character is used then no matter what extension is !
Your shell is a program. It has variables, one of them is $ PATH
$PATH contains A colon-separated list of directories to search for commands
If you want to see it just type $ echo $PATH in terminal.
On my computer it shows
vikram@vikram-Studio-XPS-1645:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
This means if I type command like gcc or vim it searches in above directory list.
Now just copy your shell script to any of above folder to access it from anywhere.