#!/bin/sh -u # Display PWD MAIL HOME replaced by optional command line arguments. #------------------------------------------------------------ # Syntax: # $0 [ arg1 [ arg2 [ arg3 ] ] ] #------------------------------------------------------------ # Purpose: # To demonstrate one way of doing optional command line arguments. # The output of this script with no arguments is the contents of: # $PWD $MAIL $HOME # Each argument replaces one of the outputs, up to three. # The script exits non-zero on error. #------------------------------------------------------------- # Student Name: Ian! D. Allen # Algonquin EMail Address: alleni # Student Number: 000-000-000 # Course Number: DAT2330 # Lab Section Number: 010 # Professor Name: Ian! D. Allen # Assignment Name/Number/Date: Sample Assignment Label # Comment: This is a sample assignment label. # see http://teaching.idallen.com/assignment_standards.html #------------------------------------------------------------- # Set standard search path and umask. # PATH=/bin:/usr/bin ; export PATH umask 022 # Make sure we have zero to three command line arguments. # If not, echo the count and incorrect input back to the user on stderr. # (The shell construct ${*-} prevents errors about "parameter not set" # if no arguments are given on some versions of Unix. Linux can use $* ) # if [ $# -gt 3 ] ; then echo 1>&2 "$0: Expecting 0-3 arguments, found $# (${*-})" exit 1 fi # Optional: Echo the user's input arguments back to the user before using them. # echo "Your argument list is: ${*-}" # Set each of the three output variables depending on whether there is or # is not a command line argument for it: # if [ $# -ge 1 ] ; then out1="$1" else out1="$PWD" fi if [ $# -ge 2 ] ; then out2="$2" else out2="$MAIL" fi if [ $# -ge 3 ] ; then out3="$3" else out3="$HOME" fi # Output the three variables. # echo "$out1 $out2 $out3" # The script exits with exit status of last command executed.