using ksh on an AIX 7.2 system
I have the following inputfile:
line1
line2
line3
I have the following code (rather simplified)
cat infile | while read strA ; do
echo "strA: $strA"
mail -s"check script strA: $strA" me@mailserver.com
done
"mail" seems to read from STDIN, what stops the loop after the first line.
Result is:
line1
=>sending mail
When I let "mail" read from /dev/null, it works:
mail -s"check script strA: $strA" me@mailserver.com </dev/null
BUT this way I get Warnings "No Message Body"
When I give a not empty dummyfile it also works`
mail -s"check script strA: $strA" me@mailserver.com </tmp/anyexistingfile
BUT I do not want to send some rubbish
Is there another way to prevent reading from STDIN and exiting the loop?
Any secret mail-option? (I can't find some)
Thank you very much in advance
(hmmm ... took me 10 minutes to describe the problem and 20 minutes to format the text)
echo See subject. | mail...
. Or evenecho | mail...
to make the body an empty line. – Stéphane Chazelas Aug 10 '21 at 05:54IFS= read -r line
, and to print arbitrary data:print -r -- "$data"
. Without those-r
(or withecho
), backslash characters receive a special treatment. – Stéphane Chazelas Aug 10 '21 at 05:59about syntax: Thank you for that tip. But in 20 years I always used "cat file | while read ...." without ever having a problem. – Rudi Aug 10 '21 at 06:26
mailx
.mail
is not a standard command. Some systems have one (or sometimes aMail
one) though not all support a-s
option to set the subject. – Stéphane Chazelas Aug 10 '21 at 06:30