#!/bin/sh #this script checks for command line arguments #this script also demonstrates the if-then-else control structure #this line uses the test builtin to check if the number of command #line arguments ($#) = 1 you can also use -eq if you are checking #for an integer #if you are writing a script that requires command line arguments #you must first check for the correct arguments and then supply #an error message or read in more argments see p. 338 if test $# = 1 then echo hey you entered a command line argument else echo you must enter exactly one command line argument exit 1 fi #the exit 1 exits the program with abnormal terminate #normal termination is for a program to exit 0, if you #go to the command line and type echo $? you can see the exit status #of the last program run #otherwise the program will continue to the next structure #now you can look to page 372 for the differentoptions to test #a file if test -f "$1" then echo "$1 is a regular file in the working directory" else echo "$1 is NOT a file in the working directory" fi #this is normal program termination #CSC128: Shell Scriptsa - Command line Arguments