Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want the output of this script to be a body of the email message but I don't want to redirect it to a file first and then to an email, basically no external login/output files - all action should be done within the script itself - is it possible to do it?



email() {

        echo "Results:"


for i in $(ls -1 test); do

if [ -f "test/$i" ]; then
        echo "'$i' it's a file."

        echo "'$i' it's a directory."


email | mail -s "Test"


$ ./ 
'd1' it's a directory.
'f1' it's a file.
share|improve this question

closed as off-topic by Janne Pikkarainen, HBruijn, HopelessN00b, mdpc, Jenny D Jul 10 '14 at 5:24

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

This question appears to be off-topic. – HopelessN00b Jul 8 '14 at 21:21
up vote 2 down vote accepted

You just need to move down the } to enclose the for loop as well, to get everything into the mail body.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.