10-11-2012, 10:51 AM
UNIX Shell Programming
UNIX Shell Programming.ppt (Size: 201.5 KB / Downloads: 35)
Shell scripts
A shell script is a text file with Unix commands in it.
Shell scripts usually begin with a #! and a shell name (complete pathname of shell).
Pathname of shell be found using the which command.
The shell name is the shell that will execute this script.
Any Unix command can go in a shell script
Commands are executed in order or in the flow determined by control statements.
Different shells have different control structures
The #! line is very important.
We will write shell scripts with the Bourne shell (bash).
Control statements
Without control statements, execution within a shell scripts flows from one statement to the next in succession.
Control statements control the flow of execution in a programming language.
The three most common types of control statements:
conditionals: if/then/else, case, ...
loop statements: while, for, until, do, ...
branch statements: subroutine calls (good programming practice), goto (usage not recommended).
Conditionals
Conditionals are used to “test” something.
In Java or C, they test whether a Boolean variable is true or false.
In a Bourne shell script, the only thing you can test is whether or not a command is “successful”.