Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Ensure that only one non-hyphened argument
- function CompanyName
- {
- for arg in $@
- do
- #Ignore arguments that begin with -
- if ! [[ ${arg:0:1} == "-" ]]
- then # argument does not begin with a hyphen
- if [[ $CompanyName ]]
- then
- 1>&2 echo "Error: Only one Comppany Name Permitted."
- exit 2
- fi
- CompanyName=$arg
- fi
- done
- }
- #Check if a variable is a valid positive integer
- function numberp
- {
- if [[ $# -ne 1 ]]
- then
- 1>&2 echo "Error in argnum to numberp"
- exit 2
- fi
- re='^[0-9]+$'
- if [[ $1 =~ $re ]]
- then
- return 0
- else
- return 1
- fi
- }
- #Add all number that follow a -a argument
- function AddNumbers
- {
- Total=0
- for arg in $@
- do
- if [[ ${arg:0:2} == "-a" ]]
- then
- value=${arg:2} #everything after the -a
- if numberp $value
- then
- Total=$(( $Total + $value ))
- else
- 2>&1 echo "Error: $value is not a number"
- exit 3
- fi
- fi
- done
- }
- #Main Routine
- CompanyName $@
- AddNumbers $@
- echo "$CompanyName owes me \$$Total!!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement