The simple answer there is to rename myscript.sh to myscript.
e.g.
Completely omit/remove the .sh part of the filename. Your script will still run.
Or alternatively - you could create a symbolic link to your script.
To create a symbolic link - open a terminal and navigate to wherever you've put your script (~/bin/, or /usr/local/bin/) and then use:
Code:
ln -sT myscript.sh myscript
Where myscript.sh is the name of the script and myscript is the link-name.
If you use a symbolic link, you will be able to run the script using the link:
or by using the scripts full file-name:
IMPORTANT:
Whenever you start installing scripts to directories in your $PATH and want to run them as standalone commands in the shell - You need to ensure that the first line of each script always contains a shebang to tell the shell which interpreter should be used to run it.
e.g.
For a bash script:
For a generic POSIX compliant shell-script that uses no shell-specific features/extensions.
For a python3 script:
etc. etc.
The shebang line must ALWAYS be the very first line in a script.
Shebang line first, then some comments describing the script, then the body of your script itself.
Also note, I have used /usr/bin/env {name_of_interpreter} in the above examples for a reason.
If you plan to distribute your scripts, or use them on multiple machines - instead of using a hard-coded path to an interpreter, it is wise to use /usr/bin/env {name_of_interpreter} - to allow env to resolve the correct path to the required interpreter.
Some distros install certain commands to different directories. e.g. sometimes bash (or one of the other common interpreters) is in /bin/, other times it might be in /usr/bin/.
And if the user helps to develop an interpreter (bash, ruby, python etc) - they may even have their personal environment set-up to use a custom version of it in ~/bin/, or on some other custom path.
So using /usr/bin/env to determine the correct path to an interpreter is a great way to make your script a little more portable.
The reason I do this is because I'm lazy. I like to write a script and make it as generic and useful as possible, without having to edit it whenever I copy it to a different machine. So env helps facilitate my laziness!