problem with variable expansion in shell script

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 12
Reputation: chunchuwar is an unknown quantity at this point 
Solved Threads: 0
chunchuwar chunchuwar is offline Offline
Newbie Poster

problem with variable expansion in shell script

 
0
  #1
Oct 27th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: problem with variable expansion in shell script

 
0
  #2
Oct 27th, 2007
Shell Scripting Syntax (Toggle Plain Text)
  1. cat dailystatus.txt| mail -s "Daily Server Status Report-${yr}-${mm}-${dd}" root@ecms.co.in
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 149
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: problem with variable expansion in shell script

 
0
  #3
Oct 28th, 2007
it should not matter if you put $yr or ${yr}. Show your entire code that defined the variables..
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: problem with variable expansion in shell script

 
0
  #4
Oct 28th, 2007
Originally Posted by ghostdog74 View Post
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 12
Reputation: chunchuwar is an unknown quantity at this point 
Solved Threads: 0
chunchuwar chunchuwar is offline Offline
Newbie Poster

Re: problem with variable expansion in shell script

 
0
  #5
Oct 29th, 2007
Thanks all,
It works with ${yr} i.e. putting variables in curly braces.
vinod
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1943 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC