Search code examples
bashhttp-redirectmutt

redirection bash: content from variable, not from file


i am using mutt to create and send mails from a bash script.

like this:

$ mutt -s SUBJECT MAIL_TO_ADDRESS < BODY_CONTENT_FILE

So i always have to write a file before calling mutt, is there a solution to pass information directly from script or shell variable ?


Solution

  • Sure.

    For literal content, you can use a here-document:

    mutt -s "$SUBJECT" "$ADDRESS" <<EOF
    body of message goes here
    and all of it is included
    until you have a line with the terminator
    which is whatever you put after the `<<`
    in this case,
    EOF
    

    Note that parameters will be expanded inside the here-document as if it were a double-quoted string, unless you quote the terminator (with e.g. <<"EOF"), in which case it will be treated as a a single-quoted string instead.

    If it's a short message, or already in a variable, it's probably easier to use a here-string instead:

    mutt -s "$SUBJECT" "$ADDRESS" <<<"$BODY"