E N D
1. CSCI 553: Networking III Unix Network ProgrammingSpring 2006 Introduction to Unix Shell Scripts
2. Unix Shells
3. Unix Shells
4. Bourne Shell First popular Unix shell
Proprietary, not available in free distributions
bash is a reimplementation
5. Korn Shell (ksh) superset of the bourne shell
improves bourne shell job control, command line editing and programming features
All of which have been incorporated into free implementations, and new implementations of csh (tcsh) and bourne shell (bash)
6. C Shell (csh) Written after the korn shell
Purpose was to provide scripting language that adheres more closely to the C language syntax, but in a scripting language
7. Bourne Again Shell (bash) Free software reimplementation of bourne shell, but really borrows from korn and csh
attempt to creat a best of all shells
extends the bourne shell (and korn shell) plus borrows from c shell
Because of availability on Linux, may be displacing csh and ksh as most used and well known
8. bash More on programming in bash
9. Start-up Bash is a Unix program.
When a bash shell starts, it executes commands in the file .bashrc in your home directory
except when started as a login shell, then it runs .bash_profile
10. Variables bash has environment variables, as weve discussed, to access:
11. Exporting Variables In all shells, variables are local to the specific shell and, unless otherwise specified, are not passed to subshells.
You must export a shell variable for its value to be still set in a subshell.
In bash (and bourne shell) use export
12. Command Shortcuts As with C shell and Korn shell, bash allows you to define your own commands, using the alias built-in
13. Other bash features If you have not discovered them, you should also exlore:
command history (up arrow is simplest example)
command editing (can use emacs or vi style)
set o vi tells the shell to use vi style command editing
Autocompletion (use the tab key to complete commands and file names while typing, especially useful for long path names)
14. Programming the bash shell arithmetic is a built-in in bash shell (unlike some previous shells)
15. An example bash program, demonstrating arithmetic and conditional expressions
16. String comparisons You may manipulate strings in bash, using these conditional operators:
17. File-Oriented Expressions Scripting languages are mainly useful for manipulating and processing text files. Usually have advanced file-oriented handling expressions.
18. File-oriented Expressions
19. Control Structures Control structures allow programming logic
Similar to those in Bourne and Korn shell
20. Control Structures case .. in .. esac
21. Control Structures for .. do .. done
22. Functions Syntatically the same as Korn shell functions.
23. Function Example [dharter@corvus ~]$ cat funcex.bash
f () # two-parameter function
{
(( returnValue = $1 * $2 ))
return $returnValue
}
f 3 4
result=$?
echo "return value from function was $result"
[dharter@corvus ~]$ ./funcex.bash
return value from function was 12