#!/bin/sh -u # # $0 [ args... ] # # A script that prompts the user for an output file name and then # echoes all its command line arguments into that file. # # WARNING: Many of the comments in this file are "Instructor-Type" # comments and are *not* appropriate for real scripts. Do not put # "Instructor-Type" comments into the scripts that you submit for marking. # I put them in my example files because I am teaching you how to # write scripts; do not submit my teaching comments back to me again. # Read the week7.txt notes for more details on good comment style. # # -IAN! idallen@ncf.ca # June 20 2001 # All scripts must start with lines similar to these two. # This script doesn't use any system or GUI commands, so all the # commands should be available in the standard Unix directories. # # The script isn't one that requires its output files to be protected, # so it uses the standard Unix umask. # export PATH=/bin:/usr/bin umask 022 date # Print some information about the script and its arguments. # Note that you don't need to escape single quotes inside double # quotes; the double quotes already do the escaping. # The "-u" option to /bin/sh (on the first line, above) will cause this # script to die if there are not at least two command line arguments. # I want my scripts to stop if arguments are missing or undefined. # echo "$0: I am process ID $$ and I have $# command line arguments." echo "The first command line argument is '$1'." echo "The second command line argument is '$2'." # Prompt for (on standard error!) and read an output file name. # echo 1>&2 "Please enter an output file name:" read filename # Put all the arguments into the output file. # For the "echo" command, "$@" would work just as well. # echo "$*" >"$filename" # Print a chatty exit message and exit. # Note that you don't need to escape single quotes inside double # quotes; the double quotes already do the escaping. # echo "I have put all $# command line arguments into file '$filename'." echo "Goodbye!" # Since this script doesn't set an explicit exit status using the # "exit" command, the script exits with the status of the last command # that it ran, above.