user3086014
user3086014

Reputation: 4511

How to insert the current date in mail command in linux?

I am sending the content of a file using mail command to a user. I want to send the current date in the subject. I have defined the variable today_date as current system date, but it is not displaying the current date in subject. Instead, it is displaying the variable name.

Here's the command:

mail -s 'VM Snapshot $today_date' j@nom <  "$EC2_HOME/SnapshotsLatest_$today_date"

Upvotes: 1

Views: 5333

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174672

Only variables encapsulated in " " will be evaluated, if you wrap your strings in single quotes it is taken literally:

burhan@sandbox:~$ echo '$PATH'
$PATH
burhan@sandbox:~$ echo "$PATH"
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

So, you need:

mail -s "VM Snapshot $today_date" j@nom < "$EC2_HOME/SnapshotsLatest_$today_date"

Upvotes: 2

Related Questions