Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-08-2010
Registered User
 

Join Date: Sep 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
How to pass a parameter with double quotes around it to a command

In a bash script, I need to pass a parameter that has space in-between using double quotes as follows:


Code:
CMD="SomeExecutable"

# Parameter that has a space in-between

Code:
PARAM1="TIMO 2"
 
CMD_IN="--name=\"$PARAM1\""
 
CMD_OUT=`$CMD $CMD_IN`

expected/required command execution:

Code:
SomeExecutable --name="TIMO 2"

But, what i see is:

Code:
SomeExecutable '--name="TIMO' '2"'

Why? How do I fix it ?

Thank you!

Last edited by Scott; 09-09-2010 at 11:57 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 09-08-2010
Aia's Avatar
Aia Aia is offline
Registered User
 

Join Date: May 2008
Posts: 112
Thanks: 10
Thanked 25 Times in 24 Posts
Thumbs up


Code:
variable='var="value plus spaces"'

The Following User Says Thank You to Aia For This Useful Post:
Timo (09-09-2010)
Sponsored Links
    #3  
Old 09-09-2010
Registered User
 

Join Date: Sep 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks for the response.
Are you suggesting


Code:
CMD="SomeExecutable"
CMD_IN='--name="TIMO 2"'
CMD_OUT=`$CMD $CMD_IN`

Still, I get the following


Code:
SomeExecutable '--name="TIMO' '2"'

Not what is required (SomeExecutable --name="TIMO2")

Last edited by Scott; 09-09-2010 at 11:56 AM.. Reason: Please use code tags
    #4  
Old 09-09-2010
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 

Join Date: Jun 2009
Location: Switzerland - ZH
Posts: 5,352
Thanks: 130
Thanked 535 Times in 473 Posts
Hi.

I get the right answer:


Code:
$ cat SomeExecutable
echo SOME EXECUTABLE HERE
echo ARGS ARE
echo $@

$ cat T1
CMD="./SomeExecutable"
CMD_IN='--name="TIMO 2"'
CMD_OUT=`$CMD $CMD_IN`

echo $CMD_OUT


$ ./T1
SOME EXECUTABLE HERE ARGS ARE --name="TIMO 2"


Last edited by Scott; 09-09-2010 at 12:07 PM..
The Following User Says Thank You to Scott For This Useful Post:
Timo (09-09-2010)
Sponsored Links
    #5  
Old 09-09-2010
Registered User
 

Join Date: Sep 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Thank you. It works now with minor adjustment as follows:

If the SomeExecutable is like this


Code:
$ cat SomeExecutable
echo SOME EXECUTABLE HERE
echo ARGS ARE
echo "P1="$1
echo "P2="$2

Then the output is,

Code:
SOME EXECUTABLE HERE ARGS ARE P1=--name="TIMO P2=2"

Fixing that required the following:


Code:
$ cat T1
CMD="./SomeExecutable"
CMD_IN='--name="TIMO 2"'
CMD_OUT=`$CMD "$CMD_IN"`
 
echo $CMD_OUT

Then the output is,

Code:
$ ./T1
SOME EXECUTABLE HERE ARGS ARE P1=--name="TIMO 2" P2=


Last edited by Scott; 09-09-2010 at 01:12 PM.. Reason: Please use code tags
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
unix command to insert double quotes in a delimited file Bachu UNIX for Dummies Questions & Answers 6 06-17-2010 05:48 AM
How to alias an awk command with single and double quotes? jacekmaciek Shell Programming and Scripting 2 06-03-2009 10:48 AM
ksh execute command containing double quotes pearson05 Shell Programming and Scripting 1 05-02-2008 05:25 AM
unix command to insert double quotes berlin_germany Shell Programming and Scripting 2 01-17-2007 12:07 PM
how to pass variables surrounded in double quotes to awk? cruiser AIX 4 03-24-2006 04:12 PM



All times are GMT -4. The time now is 04:12 AM.