Issues with Simply Bash Script

Need help with C, C++, perl, python, etc?

Issues with Simply Bash Script

Postby zgould » 2015-08-04 20:29

I'm new to Bash scripting, and I'm simply trying to make a "E-mail creation" script that will check to see if there is already an e-mail in the file, and if so it gives you a error. If not, it adds the e-mail. I can't get it to work, any ideas?

The script either keeps adding the same e-mail over without erroring out, or I've made it error out, but it matches the entire string (Meaning it doesn't differentiate between, or, it errors on both)

Thank you!

echo "Please Enter Username:"
read Username
sleep 2
echo "Please Enter Domain (Include @):"
read Domain
sleep 2

cmd=$(grep -Fxq "$email" $FILE)

if [ "$email" == "$(cat $FILE)" ];
echo "Already Exists"
echo -e "$email \t" >> /etc/postfix/sender_dependent_relayhost


echo "E-mail $email has been added"
sleep 1
echo -e "E-mail has been added. Be Well"
Posts: 1
Joined: 2015-08-04 20:25

Re: Issues with Simply Bash Script

Postby dasein » 2015-08-04 23:26

I'm not 100% convinced that this isn't a homework problem, so pardon me if I don't do more than point you in the right direction...

My entirely rhetorical question to you is: what's that grep doing in there? (To be clear, I'm not saying that it does--or doesn't--belong in there; I'm suggesting that once/if you figure out what the grep is doing, you'll be one step closer to seeing the underlying problem.)
User avatar
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Issues with Simply Bash Script

Postby GarryRicketson » 2015-08-05 15:21

Code: Select all
man grep

might help, in understanding what the grep command does.
User avatar
Posts: 5877
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests