9090
9090

Reputation: 1

problem with for loop in BASH script

I'm trying to execute the following loop inside my script in order to send mail to all users in a certain file that I write in earlier in the script. I check if the file $eUsers is not empty I execute the following:

for name in `cat $eUsers | cut -d' ' -f2`
do
echo "message" > /letter
cat /letter | mail -s "message" $name
done

However, when I use that code in my script, after writing in the file $eUsers, it goes into an infinite loop. I dont' understand why it's doing so. In the original file, the infinite loop seems to occur because of the line cat /letter | mail -s "message" $name.

Upvotes: 0

Views: 342

Answers (1)

SiegeX
SiegeX

Reputation: 140237

#!/bin/bash

while read junk name; do
  echo "message" | mail -s "message" "$name"
done < "$eUsers"

Upvotes: 2

Related Questions