Korn Shell Tutorials
Zipped file containing all the scripts: Lessons.zip
(last updated 11/25/2009)
- Tutorial 1 Covers:
- Finding out where the korn shell (ksh) interpreter is.
- Printing to the terminal screen with the "print" statement
- Inserting comments with the #
- example1.ksh: Korn shell script for this lesson.
- Tutorial 2a Covers:
- Defining a variable: VarName="Value"
- Accessing the value of a variable with $VarName
- Lesson2a.ksh: Korn shell script for this lesson.
- Tutorial 2b Covers:
- How to prompt the user for input: print -n
- Assiging input from the keyboard to a variable: read VarName
- ReadingInput.ksh: Korn shell script for this lesson.
- Tutorial 3 Covers:
- Good scripting practices:
- Writing out generally the flow of the script before hand.
- Writing small chunks of code at one time.
- Putting comments into your scripts.
- Turning on debugging for whole script with: #!/bin/ksh -x
- Turning on/off debugging in parts of the script with set -x and set +x.
- Debugging1.ksh: 1 of 2 Korn shell scripts for this lesson.
- Debugging2.ksh: 2 of 2 Korn shell scripts for this lesson.
- Tutorial 4 Covers:
- Arrays - Lists of things.
- Create an array by creating an element in an array.
For example: ArrayName[PositionFromTop]=Value
For example: ColorsOfRainbow[0]="Red"
- Arrays.ksh:Korn shell script for this lesson.
- Tutorial 5 Covers:
- Basic Math
- Adddition, Subtraction, Multiplication, Division, & Remainder
- Moving through an array.
- BasicMath.ksh:Korn shell script for this lesson.
- Tutorial 6A Covers:
- Basic "if" statement
if (( math test ))
then
commands
more commands
fi
- IfMath1.ksh:Korn shell script for this lesson.
- Tutorial 6B Covers:
- Compound if statements with && and ||
if (( (math test 1) && (math test 2) ))
then
commands
more commands
fi
- IfMath2.ksh:Korn shell script for this lesson.
- Tutorial 6C Covers:
- Introduces the "else" statement into an if/then/fi block.
If test is true, then do block of code a, else do block of code b.
if ( test ); then
code a
else
code b
fi
- IfMath3.ksh:Korn shell script for this lesson.
- Tutorial 6D Covers:
- Introduces the "elif" statement into an if/then/else/fi block.
This video demontrates the use of elif, the ability to make
a 2nd test if the 1st test is false.
if ( test1 ); then
code a
elif ( test2 ); then
code b
fi
- elif.ksh:Korn shell script for this lesson.
- Tutorial 6E Covers:
- Introduces the "elif" statement into an if/then/else/fi block.
This lesson demontrates the use of else at the end of an elif statement.
if ( test1 ); then
code a
elif ( test2 ); then
code b
else
code c
fi
- elif2.ksh:Korn shell script for this lesson.