0

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" [email protected]

Output:

$ ./tmp.sh 
'd1' it's a directory.
'f1' it's a file.

1 Answer 1

1

It's easy:

#!/bin/bash

email() {

        echo "Results:"
        cat 
}

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" [email protected]

You need the output of your test as input of email function, note that cat is just letting it pass through.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.