Zsh. Zsh is a free and open source command interpreter that can replace Bash shell. It is one of the most comprehensive alternative shells available today, with a number of useful features not seen in other shells.
Install the GitBash tool in the Windows OS. Set the below Path in the environment variables of System for the Git installation. Type 'sh' in cmd window to redirect into Bourne shell and run your commands in terminal.
Add a "shebang" at the top of your file:
#!/bin/bash
And make your file executable (chmod +x script.sh
).
Finally, modify your path to add the directory where your script is located:
export PATH=$PATH:/appropriate/directory
(typically, you want $HOME/bin
for storing your own scripts)
These are the prerequisites of directly using the script name:
#!/bin/bash
) at the very top.chmod u+x scriptname
to make the script executable (where scriptname
is the name of your script)./usr/local/bin
folder.
/usr/local/bin
because most likely that path will be already added to your PATH
variable.scriptname
.If you don't have access to /usr/local/bin
then do the following:
Create a folder in your home directory and call it bin
.
Do ls -lA
on your home directory, to identify the start-up script your shell is using. It should be either .profile
or .bashrc
.
Once you have identified the start up script, add the following line:
PATH="$PATH:$HOME/bin"
Once added, source your start-up script or log out and log back in.
To source, put .
followed by a space and then your start-up script name, e.g. . .profile
or . .bashrc
Run the script using just its name, scriptname
.
Just make sure it is executable, using chmod +x
. By default, the current directory is not on your PATH, so you will need to execute it as ./script.sh
- or otherwise reference it by a qualified path. Alternatively, if you truly need just script.sh
, you would need to add it to your PATH. (You may not have access to modify the system path, but you can almost certainly modify the PATH of your own current environment.) This also assumes that your script starts with something like #!/bin/sh
.
You could also still use an alias, which is not really related to shell scripting but just the shell, and is simple as:
alias script.sh='sh script.sh'
Which would allow you to use just simply script.sh
(literally - this won't work for any other *.sh
file) instead of sh script.sh
.
In this example the file will be called myShell
First of all we will need to make this file we can just start off by typing the following:
sudo nano myShell
Notice we didn't put the .sh
extension?
That's because when we run it from the terminal we will only need to type myShell
in order to run our command!
Now, in nano the top line MUST be #!/bin/bash
then you may leave a new line before continuing.
For demonstration I will add a basic Hello World!
response
So, I type the following:
echo Hello World!
After that my example should look like this:
#!/bin/bash
echo Hello World!
Now save the file and then run this command:
chmod +x myShell
Now we have made the file executable we can move it to /usr/bin/
by using the following command:
sudo cp myShell /usr/bin/
Congrats! Our command is now done! In the terminal we can type myShell
and it should say Hello World!
You have to enable the executable bit for the program.
chmod +x script.sh
Then you can use ./script.sh
You can add the folder to the PATH in your .bashrc
file (located in your home directory).
Add this line to the end of the file:
export PATH=$PATH:/your/folder/here
You can type sudo install (name of script) /usr/local/bin/(what you want to type to execute said script)
ex: sudo install quickcommit.sh /usr/local/bin/quickcommit
enter password
now can run without .sh and in any directory
Add . (current directory) to your PATH variable.
You can do this by editing your .profile file.
put following line in your .profile filePATH=$PATH:.
Just make sure to add Shebang (#!/bin/bash
) line at the starting of your script and make the script executable(using chmod +x <File Name>
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With