#!/bin/sh -u # Display on standard error the individual arguments on the command line. # ------------------------------------------------------------------ # Syntax: # $0 [args...] # ------------------------------------------------------------------ # Purpose: Count and display each argument to this shell script. # It also displays the command name, which is often referred to as # "Argument Zero" ($0) but is never counted as a command argument. # All output appears on "standard error", not "standard output". # ------------------------------------------------------------------ # Student Name: Ian! D. Allen # Algonquin EMail Address: alleni # Student Number: 000-000-000 # Course Number: XXX 0000 # Lab Section Number: 099 # Professor Name: Dennis Ritchie & Brian Kernighan # Assignment Name/Number/Date: Exercise 123, due Sept 1, 2010 # Comments: This is a sample assignment label. # ------------------------------------------------------------------ # I! Comments flagged with "I!" are "instructor-style" comments that # I! explain some aspect of script writing to people who are new to it. # I! Since these comments explain things that are obvious to someone who # I! understands scripts, they are not comments that should appear in # I! production code, or in code submitted by students for marking. # I! Delete all I! comments from any code you hand in. # Set the search path for the shell to be the standard places. # Set the character collating sequence to be numeric ASCII/C standard. # Set the language and character set to be ASCII/C standard. # Set the umask to be non-restrictive and friendly to others. # PATH=/bin:/usr/bin ; export PATH LC_COLLATE=C ; export LC_COLLATE LANG=C ; export LANG umask 022 # I! The $0 variable contains the name of this script, sometimes called # I! "argument zero". It is not an argument to the script itself. # I! The $# variable contains a count of the number of command line arguments. # I! The script name is not counted as an "argument" to the script; # I! only arguments 1 and up are counted as arguments to the script. # I! The syntax "1>&2" means "on this line, send what would normally appear # I! on stdout to stderr" - the output of the line goes to stderr. # echo 1>&2 "$0: This script has $# command line arguments." echo 1>&2 "Argument 0 is [$0]" # Now display all of the command line arguments (if any). # These ($1, $2, etc.) are the real command line arguments to this script. # count=0 for arg do count=$(( $count+1 )) echo 1>&2 "Argument $count is [$arg]" done # I! zero is a good/success return status for a command that succeeds. # exit 0