Shell scripts A shell script is just a collection of shell commands that are stored in a file. For example, put the following into a file "foo": who | sort By typing "sh foo", you will run the commands in the file foo. Unfortunately, most of what we do with the shell is "shell specific". That means that it will vary from shell to shell. We will be using Bourne shell, but many people use C-shell instead. As an example of the differences between shells, here is how you do variable assignments in Bourne shell and C-shell: Bourne shell: foo="hello world" C-shell: set foo="hello world" Because the syntax is different from shell to shell, you must be careful that you use the right shell to run your scripts. This means that if you are going to experiment interactively with shell scripting, you should first start an interactive Bourne shell: type "sh". Input and output: UNIX shells use "|", "<", ">", ">>", and "<<" to describe operations on the output and input for commands. | The vertical bar (called a "pipe") is used to take the output from one command and turn it into the input for the second command. Try the following: who | sort # try this on harper "who" lists some statistics about the current users of the machine (output). "sort" reads that output and sorts it. The pipe binds their input and output together. > The greater than symbol is used to put the output from a command into a file. For example: who | sort >some_file stores the output from the "who | sort" in the file "some_file". < The less than symbol is used to take input from a file. For example "who | sort > some_file" could be broken down into the following sequence of commands: who >temp_file sort some_file rm temp_file >> The double greater than symbol is quite similar to the single greater than symbol. The only difference is that if the output file already exists, then the output from the current command is appended to it rather than having the file "truncated" and then having its contents replaced. << The double less than symbol is quite different from the rest. Its use is primarily for shell scripts (which we will get to soon), but it can be experimented with from the shell. It is called "heredoc". An example of its use is: cat <