Ch11 Shell Programming
Ch11 Shell Programming
PROGRAMMING
INTRODUCTION
• Kernel
The computer program that forms the core of your computer's
operating system.
It is responsible for managing the following resources:
1. File management
2. Process management
3. I/O management
4. Memory management
INTRODUCTION
• Shell
It plays the role of converting the human-readable commands from the
user to kernel language.
There are two classifications of shell:
• STDIN
The STDIN file descriptor is used to reference standard inputs to the
shell.
The input redirect signal (<) commands the shell to replace the file
referenced in the redirection with the standard file descriptor.
It will retrieve the file's data, just like the user would have typed on the
keyboard.
INPUT/OUTPUT TECHNIQUES
• STDOUT
The STDOUT file descriptor is used for referencing the standard output
in the shell.
The standard output for a terminal interface is the terminal monitor.
The STDOUT file descriptor receives outputs from most bash
commands by default.
However, programmers can change redirect the output by using
output redirection.
INPUT/OUTPUT TECHNIQUES
• STDERR
STDERR file descriptor is the one that the shell uses to handle error
messages.
It is used to reference the standard error output.
STDERR will redirect all the error messages to the same place as
STDOUT.
Hence, all error messages will go to the monitor by default.
INPUT/OUTPUT TECHNIQUES
SYSTEM-DEFINED VARIABLES
• They are variables that the Linux operating system creates and
maintains.
• The command “$ set“ is used to display these variables.
System Defined Variables Meaning
BASH=/bin/bash Shell Name
BASH_VERSION=4.1.2(1) Bash Version
COLUMNS=80 No. of columns for the screen
HOME=/home/apjtech Home Directory of the User
LINES=25 No. of columns for the screen
LOGNAME=APJTECH Logging name
USER-DEFINED VARIABLES
$
myvar=greetings $ myvar1=”greetings all!”
$ mycount=1
HOW TO ACCESS A VARIABLE?
• The shell script de-references a variable name by adding the prefix '$.’
• To print the variable's value, use the 'echo' command.
$ echo $myvar
greetings
HOW TO ACCESS A VARIABLE?
• If there is the ‘expr’ command, the script will treat the variable as a
numeric value.
• In case the variable is not followed by a space, surround it with spaces.