Unix commands can be placed into a file just like DOS commands. The commands
in the file are executed in sequence as though you were typing each one
from the command line
and pressing enter after the command.
The commands become a user-defined "Unix command".
To create a shell script,
- Open your favorite editor (nano or vi) and create a file with any name
you choose. The filename will become the shell script's name and thus the
name of a user-defined unix utility.
- Good scripting practice suggests that the first line of the script be:
- #!/bin/sh
This Unix command tells the interpreter that is running the command, which
Unix shell to use. Different shells (Bash, bourne, cshell) have different
syntax. For the Bash and bourne shell use /bin/sh, for the
cshell use /bin/csh/.
A new shell will begin executing and the commands in your script
will be executed in this new shell.
- type in
echo hello
echo my name
echo "my name"
echo $1
- Save the file
- Change the permissions on the file so that you can execute the file.
chmod u+x file
- Issue the command file
- Issue the command file bye
- Help with the example
Give this a try ... write a script that outputs:
Hi username happy day of the week