Input/output
- Every process starts with a standard input (stdin),
standard output (stdout), and standard error
(stderr) stream, each connected to some device.
- The standard stream of a command may be redirected.
- > name - The file name is used as standard output
- >> name - Like >, but appends output to the
end of name.
- A series of commands joined by | characters forms a
pipeline.
The stdout of the command in a pipeline is connected to
the stdin of the next.
- stderr output may be directed through a pipe with
the stdout using |& (in newer bash versions)
The Idea of Scripts
- A shell script is a sequence of shell commands
- Lines starting with # are comments
- $1, $2, etc., are arguments to the script
- Two ways to run scripts
- source <script file> or ./<script file>
- Add a line that specifies which shell should be used to execute
the commands on its first line, with a leading #!,
e.g., #!/bin/bash.
Make the file executable (with chmod +x your_file_name).
- LookingForInts
- Sample bash script
Exercises
- How many builtin commands are there in your shell?
- What does the source command do?
Exam Style Questions