944,066 Members | Top Members by Rank

Ad:
Oct 27th, 2007
0

problem with variable expansion in shell script

Expand Post »
Dear all,
I have written a small script which will send me mail on status of server.
I have tested it working fine. I am facing only with message subject

The last part of my script is as below,

cat dailystatus.txt| mail -s "Daily Server Status Report-$yr-$mm-$dd" root@ecms.co.in

The script run perfectly . The variable yr, mm. dd are defined and that is not a problem I have tested it too. But when I receive the mail , I got the subject heading as "Daily Server Status Report-$yr-$mm-$dd" . The variable are not getting replaced by the values,
So I feel that it may not be allowed to put variables with mail command.

Is there is any way so that subject can be read from file. Or any other idea on this.
Thanks
Vinod
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chunchuwar is offline Offline
12 posts
since Oct 2007
Oct 27th, 2007
0

Re: problem with variable expansion in shell script

Shell Scripting Syntax (Toggle Plain Text)
  1. cat dailystatus.txt| mail -s "Daily Server Status Report-${yr}-${mm}-${dd}" root@ecms.co.in
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Oct 28th, 2007
0

Re: problem with variable expansion in shell script

it should not matter if you put $yr or ${yr}. Show your entire code that defined the variables..
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006
Oct 28th, 2007
0

Re: problem with variable expansion in shell script

Click to Expand / Collapse  Quote originally posted by ghostdog74 ...
it should not matter if you put $yr or ${yr}.
Maybe not, but it is still a good practice to get into, especially when using variables mixed in with other characters where the variable does not have whitespace on both sides. But, considering that he is actually getting "-$yr-" (which is the first variable) tells me that the script is not recognizing those "strings" as variables, at all, which the braces can help with.

Edit: If it were that the variables were defined wrong, he would probably wind up with "Report---".
Last edited by masijade; Oct 28th, 2007 at 8:38 am.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Oct 29th, 2007
0

Re: problem with variable expansion in shell script

Thanks all,
It works with ${yr} i.e. putting variables in curly braces.
vinod
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chunchuwar is offline Offline
12 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Compare two dates using Shell Programming
Next Thread in Shell Scripting Forum Timeline: call the constructor of java class from script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC