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:
sudo 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/
Just to make sure that the machine can execute it properly we will need to reboot the machine
I used sudo shutdown -r now
Congrats! Our command is now done! In the terminal we can type myShell
and it should say Hello World!
$HOME/bin
- if you don't already have one, add it to your PATH (near the front). Put the scripts (and any other programs) you want to execute directly without specify the pathname in here, or symlinks in here to where the actual programs are. – Jonathan Leffler Jan 8 '12 at 18:28mv example.sh example
and thenexample
should work on its own. – PJ Brunet Dec 13 '16 at 6:14