Shell Scripting
Prof. Brian D. Davison
Computer Science & Engineering, Lehigh University
Announcements
- New project online (scripting!), due Thursday, March 24
- Today's schedule
- Short quiz #7
- Return Project #4, Range 83-100, average=98.7
- Continue Shell Scripting
Ridirecting Input
- Sometimes you want to be able to pass multiline data into a program.
- If that data is in a file, you redirect stdin
- If that data is the output of another program, you use a pipe to connect them
- But what if you want to dynamically generate that data?
- You could use something like "echo line-n >> file"
- and then run as "program < file"
- A better answer is the "here document"
Function variables and return values
Shell Scripts All Around
- It turns out that you run shell scripts all the time without knowing it.
- When you login, the system runs multiple scripts, including the one in /etc/profile
- The startx program (which starts X-windows if not already running) is a script.
- Many others, such as netscape, ps2epsi, and a number in /usr/bin/ are scripts, too.
- Let's look at a few of them.
bash versus tcsh
- I "grew up" with tcsh
- Both tcsh and bash are modern, powerful shells.
- Both support
- Aliases
- Command-line editing
- Directory stacks
- Filename completion
- History
- Job control
- Key binding
- Prompt formatting
- In addition, bash supports functions!
- For some details of the differences in syntax, see Quigley Appendix B and
this quick online chart