#!/bin/sh
#this script shows the operation of command line arguments
#
CSC128: Shell Script Examples - Command line Arguments
#see ch 10 p. 337-8
# $n is the variable for command line arguments where n=1 to x
# $0 holds the name of the script that was called
# $# is the variable for the number of command line arguments
# $* is the variable to show all command line arguments space delimited
# $? returns the exit value of the last program run normal termination
# should return an exit value of 0
#note how the program will stop when I say read
#the read is also creating a new variable called newvar
echo the script you called '$0' was: $0
echo
echo "The number of command
line arguments ('$#') is: $#"
echo -n "Enter the next variable called newvar:"
read newvar
echo
echo "The first argument you entered at the command line is: $1"
echo "The second argument you entered at the command line is: $2"
echo The third argument you entered at the command line is: $3
#note that the '' cause the variable not to be evaluated see p. 321
echo 'The third argument you entered at the command line is: $3'
echo "All the arguments are: $*"
echo
#note that if I enclose the parameter in 'single quotes' it is not evaluated
#additionally, the "$@" inside of double quotes actually returns all of the
#command line args as seperate arguments where $# returns them as 1 argument
echo All the arguments are using '$@': $@
echo
echo $newvar
# notice that '$newvar' can be a single variable with spaces
#notice that if the echo statement is in "" then it can be multiple lines