user127192 user127192 - 8 months ago 59
Bash Question

Email Automation in Shell Script: Add an input when you run the script

I was able to run the script for email automation using this code:

echo 'This is a test' | mail -s 'Test mail' -- -f

However, I would like to be able to add an additional value when I run the script i.e ./ value—the value is a variable that I need to include on the email message body.

Thank you,


You can do this:



echo $body | mail -s 'Test mail' -- -f

then call the script as you requests ./ value but don't forget to make it executable using chmod +x

Update: If you need to treat the email as a variable then you need to add it as email=$2 just like we did with body=$1 but the email will be the second argument in this case and same goes for the subject.