#!/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. # # NOTE: This script fragment is incomplete - it does not follow all # the script guidelines set out in "script_style.txt". # # -IAN! idallen@idallen.ca # 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