#!/bin/sh -u # Perform several tests on the first argument to this script. #------------------------------------------------------------ # Syntax: $0 [filename] #------------------------------------------------------------ # Purpose: Perform several tests on a pathname argument. # If no arguments, do the tests on /etc/passwd instead. #------------------------------------------------------------ # 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 Assignemnt Label # Comment: This is a sample assignment label. # see http://teaching.idallen.com/assignment_standards.html #------------------------------------------------------------- # Set the search path for the shell to be the standard places. # Set the umask to be non-restrictive and friendly to others. # PATH=/bin:/usr/bin ; export PATH umask 022 # First, find out which pathname we are going to be testing. # If there is no command line argument, use a built-in pathname. # (This could use an "elif" to avoid nesting the two IF statements.) # if [ $# -eq 0 ] ; then # use a default because first argument is missing path="/etc/passwd" echo "Script has no arguments; using default path: $path" else if [ $# -eq 1 ] ; then # use the first argument as the pathname path="$1" echo "Using first argument: $1" else echo 1>&2 "$0: Expecting 1 optional pathname argument," \ "found $#: ($*)" exit 1 fi fi echo "You are using pathname '$path'." if [ -e "$path" ] ; then echo "The path '$path' exists" else echo "The path '$path' does not exist" \ "(or is missing or inaccessible)" fi if [ -d "$path" ] ; then echo "The path '$path' is a directory" else echo "The path '$path' is not a directory" \ "(or is missing or inaccessible)" fi if [ -f "$path" ] ; then echo "The path '$path' is a plain file" else echo "The path '$path' is not a plain file" \ "(or is missing or inaccessible)" fi if [ -r "$path" ] ; then echo "The path '$path' is readable" else echo "The path '$path' is not readable" \ "(or is missing or inaccessible)" fi if [ ! -w "$path" ] ; then echo "The path '$path' is not writable" \ "(or is missing or inaccessible)" else echo "The path '$path' is writable" fi if [ ! -x "$path" ] ; then echo "The path '$path' is not executable" \ "(or is missing or inaccessible)" else echo "The path '$path' is executable" fi # exit with a good return code # exit 0