Operating System - HP-UX
1824918 Members
3795 Online
109677 Solutions
New Discussion

Using Mailx with variables

 
SOLVED
Go to solution
Beannie
Advisor

Using Mailx with variables

I have a script with set variable's that are also being used with the mailx command (below). All variables (except $MAIL2) are working OK. $MAIL2 is my receipent (or in this case... receipents):

#mailx -m -s "$i ORDERS for $DATE2" $MAIL2 < $i.txt

mailx works find if I hard cod the address but in this case, that is not feasible for me which is why I choose to use a variable.

Anyone know if it's possbile? Thanks.
1 REPLY 1
Bill Hassell
Honored Contributor
Solution

Re: Using Mailx with variables

This isn't a mailx question. $Variables are part of the shell and mailx never sees them. Instead, your shell expands each variable into it's contents. To see what mailx is seeing, put echo in front:

# echo mailx -m -s "$i ORDERS for $DATE2" $MAIL2 < $i.txt

As you can see, the $i, $DATE2 and $MAIL2 have been replaced by their contents -- unless you see nothing where $MAIL2 is in the echo line. That means you had a spelling error -- MAIL2 may have been assigned a value as MAIL3. So $MAIL2 is undefined.

As with all script writing, always use set -u so the script will stop when you try to use undefined variables.


Bill Hassell, sysadmin