Variables in shell script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Variables in shell script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-03-2009
shantanuo shantanuo is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 23 September 2013, 3:07 AM EDT
Location: Mumbai
Posts: 81
Thanks: 1
Thanked 0 Times in 0 Posts
Variables in shell script


Code:
mysqldump --compact --add-drop-table -h192.168.150.80 -uroot -p somePass $combined | sed '/$combined/$table/g' | mysql $database

The sed part is not working from the above statement.
The variables combined and table are already defined and instead of showing the actual variable, it is executing the $/combined/$table in the sed part.
How do I replace the variables and then use the sed command?
Sponsored Links
    #2  
Old 09-03-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 August 2014, 5:44 PM EDT
Location: NM
Posts: 10,176
Thanks: 273
Thanked 785 Times in 734 Posts
That is becuase the single qout ' character prevents the shell from "translating" the variable. It sees it as a literal $variablename.

Change the ' to double quotes "
Sponsored Links
    #3  
Old 09-03-2009
shantanuo shantanuo is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 23 September 2013, 3:07 AM EDT
Location: Mumbai
Posts: 81
Thanks: 1
Thanked 0 Times in 0 Posts
No quotes when double quotes

When I used double quotes, the grep statement translates without any quotes.
    #4  
Old 09-04-2009
panyam panyam is offline Forum Advisor  
Registered User
 
Join Date: Sep 2008
Last Activity: 24 July 2014, 3:48 AM EDT
Posts: 1,156
Thanks: 20
Thanked 104 Times in 99 Posts
Did you get the desired output ?..

If not , post the sample input and the output your expecting .
Sponsored Links
    #5  
Old 09-10-2009
shantanuo shantanuo is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 23 September 2013, 3:07 AM EDT
Location: Mumbai
Posts: 81
Thanks: 1
Thanked 0 Times in 0 Posts
Resolved

The problem was resoved when I added the "s" in double quotes like this...

sed "s/$combined/$table/g"
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script question on variables figaro UNIX for Dummies Questions & Answers 2 04-04-2009 05:09 AM
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
Accessing variables of one shell script in another shell script looza Shell Programming and Scripting 2 06-30-2008 07:13 PM
passing two variables into a shell script? Bashar Shell Programming and Scripting 2 05-15-2007 10:00 AM
Shell Script Variables ragha81 Shell Programming and Scripting 3 08-22-2006 03:43 AM



All times are GMT -4. The time now is 05:27 AM.