Main index

Introducing UNIX and Linux


Introduction to shells

Overview
Why do we need a shell?
Shell syntax
      Types of shell command
      Simple commands
      Pipelines
      Grouping commands
      Exit status
      List commands
Arithmetic
      Operators and functions
Making decisions
      The 'test' statement
            Operators used by 'test'
      The 'if' statement
Loops
      'For' loops
      'While' and 'until' loops
Searching for files
      Arguments to 'find'
Formatted output
      Arguments to 'printf'
Passing information to scripts
      Scripts with arguments
      Parameter expansion
Summary
Exercises

Answer to chapter 7 question 3

The script must initially check that all the arguments are readable, then it can simply pass them all to cat:

for i in "$@"          # For each argument
do
   if [ ! -r "$i" ]    # if it is not (!) readable (-r)
   then exit 1         # then bomb out
   fi
done

cat "$@"               # cat the files

Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck