Here are the steps you would follow to create a simple shell script:
You have already created a text file named trial.sh, whose contents are the same as those given in this lesson, in your home
directory (/home/user1). Type head trial.sh to view the contents of the trial.sh file.
List all details of only trial.sh by typing ls –l trial.sh.
You can see that this file is not executable. Using the chmod command and the appropriate arguments, make the file
executable by a user. Use symbolic mode.
chmod u+x trial.sh
Using the ls –l command, list the file again to make sure your changes have taken place.
You can see that the file has the correct information in the first line (#!/bin/sh), and that it has the correct
permissions (-rwxrw-r). However, as you learned in the last exercise, you must first set the current path to execute
trial.sh. Update your path now.
Export this PATH to a system variable. Solution:export PATH
Execute the trial.sh file by typing trial.sh.
Note that the shell runs, and uses the date command to render on the screen. This program will run indefinitely unless you press CTRL-C to end it. End the program.
Run trial.sh again. This time, however, run it in the background. To do this, type trial.sh &. The
& character automatically runs processes in the background.
Now, with your trial.sh program running in the background, type ps to find out what types of processes are
Note that by executing trial.sh, you have also begun another sh process. This is because the sh
interpreter process executed your command. The trial.sh program is currently running in the background. Type fg
to make the trial.sh program run in the foreground again.
This program will run for 600 seconds unless you press CTRL-C to end it.
You are now back at your login shell and are not running any extra shells or processes.