Ksh Tutorials :Basics of shell scripting

Kshell Tutorials :Basics of shell scripting
Defining the Shell Type
To make a ksh script (which is a ksh program) crate a new file with a starting line like:
It is important that the path to the ksh is propper and that the line doesn not have more than 32 characters. The shell from which you are starting the script will find this line and and hand the whole script over to to ksh. Without this line the script would be interpreted by the same typ of shell as the one, from which it was started. But since the syntax is different for all shells, it is necessary to define the shell with that line.
Four Types of Lines
A script has four types of lines: The shell defining line at the top, empty lines, commentary lines starting with a # and command lines. See the following top of a script as an example for these types of lines:
# Commentary......
if [[ $file = $1 ]];then
Start and End of Script
The script starts at the first line and ends either when it encounters an "exit" or the last line. All "#" lines are ignored.
Start and End of Command
A command starts with the first word on a line or if it's the second command on a line with the first word after a";'.
A command ends either at the end of the line or whith a ";". So one can put several commands onto one line:
print -n "Name: "; read name; print ""
One can continue commands over more than one line with a "\" immediately followed by a newline sign which is made be the return key:
grep filename
sort -u
awk '{print $4}'
uniq -c >> /longpath/file
Name and Permissions of Script File
The script mus not have a name which is identical to a unix command: So the script must NOT be called "test"!
After saveing the file give it the execute permissions with: chmod 700 filename.

No comments: