Download presentation
Presentation is loading. Please wait.
Published byAntonia Johnson Modified over 6 years ago
1
Agenda Korn Shell Functions Korn Shell Variables
Korn Shell Variable Attributes Korn Shell Arithmetic Functions
2
Korn Shell The Korn shell was developped to incorporate Bourne shell as well as incorporate many features of the C shell The Korn shell also has many features including improved math processing, aliases, variable attributes and history capabilities The default shell for PHOBOS is the Korn shell.
3
Z & Bash Shells The Z shell is Linux’s equivalent to the Korn shell - Z shell is available on TUX The Bash shell has evolved to contain many of the features of both the Bourne shell and Korn shell
4
Running Shells If your system allows you access to the shell, you can switch to a shell by issuing a command. Eg. Bash bash shell zsh Z Shell sh Bourne Shell ksh Korn Shell
5
Setting a Default Shell
In some Linux and UNIX systems, you may be able to set your default shell upon logon by issuing the command: chsh
6
Korn Shell Variables The rules for Korn Shell variables are very similar as for Bourne Shell variables: $1 - $9 are positional parameters (can use ${var} this allows for greater range For user-created variables, variable name cannot begin with a digit and use assignment with an equal sign (no spaces on either side) Variables can be removed using the unset command
7
Korn Shell Variables Braces for variables can be handy to combine text together: example: SUFF=ization echo org$SUFF PREF=counter echo ${PREF}clockwise Will display organization In order for text substitution to work in front of text, braces must be used. This example will display counterclockwise
8
Korn Shell Variable Attributes
One major way in which Bourne and Korn shells differ is that Korn shell can assign attributes to variables such as: upper or lower case integer justification and width The most useful attribute is integer since the variable does not have to be converted from text to an integer during processing
9
Korn Shell Variable Attributes
The typeset command is used to set an attribute for a variable examples typeset -u var (set var to be uppercase) typeset -l var (set var to be lowercase) typeset -i var (set var to hold an integer) typeset -L3 var (set var as left justified with a width of 3) typeset -R5 var (set var as right justified - width of 5)
10
Korn Shell Arithmetic In the Korn shell, user-created variables can have an integer attribute. This makes it more efficient to perform math operations than the Bourne shell. When performing calculations in the Korn shell using these variables, two expressions are used: The let statement The convention $((..))
11
Korn Shell Arithmetic Example: typeset -i x y x=23 y=37 let result=x+y
echo $result result=$((x+y)) In first example, note how variables are set as integers. Also note with let command that no spaces are allowed In second example can use double-braces to perform math operations….
12
Z & Bash Shell Arithmetic
Syntax for Z shell arithmetic is the same as for Korn shell arithmetic Bash Shell Arithmetic: result=$[x+y] echo $result Note difference between Bash, Korn shell and Bourne shell syntax!
13
Command Substitution Syntax
The syntax rules for the Bourne, Korn (Z) and Bash shells are as follows: Bourne Shell `command` Korn (Z) Shell $(command) Bash Shell $(command)
14
Functions A function is a series of commands that are stored in computer’s main memory in order to allow quicker execution than executing a script. Functions can also be contained within a shell script. As opposed to creating a function within the shell itself, a script containing a function will run slower since it is not stored in computer’s main memory
15
Functions Example: who_is_here() >{ > date
After function entered (include brackets) type body of function at PS2 prompt - make sure to include braces. Example: who_is_here() >{ > date > echo “Users Currently Logged On:” > who -H | more >} When end brace is entered, shell prompt will appear. To run function type who_is_here
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.