To successfully write a shell script, you have to do three things:
- Write a script
- Give the shell permission to execute it
- Put it somewhere the shell can find it
Now, fire up your text editor and type in your first script as follows:
#!/bin/bash ...the script
And after saving you must make it executeable.
sudo chmod +x <path>
sudo chmod 755 <filename>
Note that it is a good idea to put your scripts in one place, so you can run them without requiring a path. If you create a bin directory in your home ( mkdir ~/bin ) the next time you login, that will automatically be included in your PATH.
mkdir ~/bin
chmod 755 ~/bin
Edit : If you want the script to be available to all users, place it in /usr/local/bin and have it owned by root with rx access by others sudo chown root:root /usr/local/bin/your_script ; sudo chmod 655 /usr/local/bin/your_script
gksudo gedit ~/.bashrc
Add the following to the end of .bashrc and save:
if [ -d $HOME/bin ]; then
PATH=$PATH:$HOME/bin
fi