first off if your want you code to look better when posting to this forum use bb code tags
http://www.daniweb.com/techtalkforums/announcement113-3.html
Bash is kind of picky, you need to use spaces with alot of stuff, but no spaces can be used when setting variables.
you need to space the following condition like this
while [ $nummail -gt 0 ]
you also need to use command substitutuion for some of your lines for example:
nummail= ls | wc -l
nummail=' expr $nummail-1' you can do substitiuion using these two different techniques, first
nummail=$(ls | wc -l)
nummail=$(expr $nummail - 1) # notice the space on both sides of the minus operater you can also use back ticks(not single quotes) for command substitution
nummail=`ls | wc -l`
nummail=`expr $nummail - 1`
you can extract the first file with a .eml extention like this, and set it to a variable like this. I am assuming you are running the script from you mail directory
email=$(ls *.eml | head -n 1) your code using a while statment works well. If you just need to do something to a list of files in a directory a for statment is much more efficient. This should work also
for email in *.eml
do
mail -s "PROVA PROVA" Administrator@dominio.loc < ${email}
done
I have never used the mail command, I just used yours as an example