Basics:
First:
You create a script with a "shebang" on the first line, this defines if it is e.g. bash, python or perl which understands the remainder of the text file.
This usually looks like: #!/bin/bash
, #!/bin/env python
or some such
Second:
Make sure the file has the x
-flag for a selection of user
, group
and/or others
(man chmod
for more detail) by use of e.g.
chmod 755 script_filename
Third:
Place it in a folder (directory) on your harddisk, on any permanently mounted storage medium.
Here mkdir -p $HOME/bin/
might be a good idea, for personal stuff.
Fourth:
make sure the folder is stated in echo $PATH
- by e.g. adding a line containing
export PATH=$PATH:/absolute/path/to/folder/
in $HOME/.bash_aliases
With all these in place your script will be accessible (executable) - in a newly launched shell (for #4 to take effect) - by only typing the name at the bash prompt.
(Note: WSL at least in first incarnation, is/was an Ubuntu by Canonical)
More detail: https://tldp.org/guides.html - in the Bash guides
#!/bin/sh
and thenchmod +x test.sh
. Also, it needs to be executed with./test.sh
if it is not in the path.