3. Shells
A shell is an environment in which we can run our commands, programs, and shell scripts.
Korn Shell /bin/ksh OR /usr/bin/ksh
4. A shell script can be executed in the following ways:
ksh shell_script_name
will create a Korn shell and execute the shell_script_name in the newly created Korn shell
environment. shell_script_name.
5. Different Types of Shells to Declare
#!/usr/bin/sh OR #!/bin/sh Declares a Bourne shell
#!/usr/bin/ksh OR #!/bin/ksh Declares a Korn shell
#!/usr/bin/csh OR #!/bin/csh Declares a C shell
#!/usr/bin/bash OR #!/bin/bash Declares a Bourne-Again shell
6. Control Structures
The following control structures will be used extensively.
if ... then Statement
if [ test_command ]
then
commands
fi
7. if ... then ... else Statement
if [ test_command ]
then
commands
else
commands
fi
8. if ... then ... elif ... (else) Statement
if [ test_command ]
then
commands
elif [ test_command ]
then
commands
elif [ test_command ]
Then
commands
.
.
.
else (Optional)
commands
fi
9. for ... in Statement
for loop_variable in argument_list
do
commands
done
14. The last part of the case statement:
*)
commands_to_execute_for_no_match
;;
is optional.
15. Using break, continue, exit, and return
It is sometimes necessary to break out of a for or while loop, continue in the next block of
code, exit completely out of the script, or return a function’s result back to the script that
called the function.break is used to terminate the execution of the entire loop, after
completing the execution of all of the lines of code up to the break statement. It then
steps down to the code following the end of the loop.continue is used to transfer control
to the next set of code, but it continues execution of the loop.exit will do just what one
would expect: It exits the entire script. An integer may be added to an exit command (for
example, exit 0), which will be sent as the return code.return is used in a function to send
data back, or return a result, to the calling script.
16. Unix Commands Review
COMMAND DESCRIPTION
passwd Change user password
pwd Print current directory
cd Change directory
ls List of files in a directory
wildcards * matches any number of characters, ?
matches a single
character
file Print the type of file
cat Display the contents of a file
pr Display the contents of a file
pg or page Display the contents of a file one page at a
time
17. Unix Commands Review (Cond…)
more Display the contents of a file one page at a
time
clear Clear the screen
cp or copy Copy a file
chown Change the owner of a file
chgrp Change the group of a file
chmod Change file modes, permissions
rm Remove a file from the system
mv Rename a file
mkdir Create a directory
rmdir Remove a directory
18. Unix Commands Review (Cond…)
grep Pattern matching
egrep grep command for extended regular expressions
find Used to locate files and directories
>> Append to the end of a file
> Redirect, create, or overwrite a file
| Pipe, used to string commands together
|| Logical OR—command1 || command2—
execute command2
if command1 fails
& Execute in background
&& Logical AND—command1 && command2—
execute
command2 if command1 succeeds