Lab - Shell
Before starting writing shell scripts at all:
- Make sure your bin directory exists.
mkdir $HOME/bin
- Check it is in the PATH.
echo $PATH
- If not, you need to
add $HOME/bin to the PATH.
- Optional:
Hide your bin directory from other users:
chmod go-rwx $HOME/bin
For every Shell script you write, go through this checklist.
To make a new program called "prog":
- Put it in $HOME/bin
- Use a text editor
to edit it.
For example a GUI editor:
gedit prog &
Or a command-line editor:
nano prog
- Make it executable:
chmod +x prog
- Run it:
prog
Exercise: d
Make a Shell script called "d" - detailed ls
Exercise: gnews
Another simple exercise:
Make a shell script called gnews.
Usage:
gnews someargument
It uses wget to grab today's news from, say,
RTE.
It then searches the page (using grep) for the argument.