Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Variables in shell script

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 09-03-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 28 May 2015, 4:54 PM EDT
Location: NM
Posts: 10,454
Thanks: 337
Thanked 862 Times in 800 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 Unix and Linux 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 Unix and Linux 09-04-2009
panyam panyam is offline Forum Advisor  
Registered User
 
Join Date: Sep 2008
Last Activity: 8 December 2014, 6:40 AM EST
Posts: 1,159
Thanks: 20
Thanked 105 Times in 100 Posts
Did you get the desired output ?..

If not , post the sample input and the output your expecting .
Sponsored Links
    #5  
Old Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 08:18 AM.