For my homework assignment, I need to send an email out specified email addresses if disk space falls below a certain threshold. I am having issues with passing the email addresses to a variable, however. The user can specify as many email addresses as they like at the command prompt. Also, if they do not include a domain, the email should still send to an "@uml.edu" address.
I am trying to solve the problem of the user entering in an unknown number of email addresses by using an array. I have never really used an array in bash, and I think I might be using incorrect syntax.
I don't know if I necessarily need to use an array to accomplish what I am doing, but it seemed to make the most sense. I have tried using a for loop to accept multiple values, and I am using a case statement to handle whether or not the user included a domain for an email address.
#!/bin/bash
email=()
for {{ x=0; $#<0; x++ ))
do
case $1 in
*@*) email[x]="$1"
shift ;;
*) email[x]="${1}@uml.edu"
shift ;;
esac
done
echo ${email[@]}
The above code is basically a test case that I would work into my main code once I get it working. The expected results would be the user could enter in one or more email addresses at the command line and then they would be displayed via the echo command.
forloop iterates over"$@", the list of command-line arguments, by default; andarr+=( "item1" "item2" )lets you append one or more items without needing to track index numbers).