I have a shell script which I want to run without using the "sh" or "bash" commands. For example:
Instead of: sh script.sh
I want to use: script.sh
How can I do this?
P.S. (i) I don't use shell script much and I tried reading about aliases, but I did not understand how to use them.
(ii) I also read about linking the script with another file in the PATH variables. I am using my university server and I don't have permissions to create a file in those locations.
These are some of the pre-requisites of using directly the script name:
sha-bang {#!/bin/bash)
line at the very top.chmod u+x scriptname
make the script executable./usr/local/bin
folder.Note: The reason I suggested to place it under
/usr/local/bin
folder is because most likely that will be path already added to yourPATH variable
.Update:
If you don't have access to the
/usr/local/bin
folder then do the following:myscripts
.ls -lart
on your home directory, to identify the start-up script your shell is using. It should either be.profile
or.bashrc
.export set PATH=$PATH:~/myscript
.Here is my backup script that will give you the idea and the automation:
Server: Ubuntu 16.04 PHP: 7.0 Apache2, Mysql etc...
change /home/user to your user directory and type: backupscript anywhere on terminal to run the script! (assuming that /usr/bin is in your path)