Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

Example:

#!/bin/bash

email() {

        echo "Results:"

}

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

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

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

done

email | mail -s "Test" an@example.com

Output:

$ ./tmp.sh 
'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 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 at 21:21

1 Answer 1

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.