How to pass a parameter with double quotes around it to a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass a parameter with double quotes around it to a command
# 1  
Old 09-08-2010
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 12:57 PM.. Reason: Please use code tags
# 2  
Old 09-08-2010
MySQL

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

This User Gave Thanks to Aia For This Post:
# 3  
Old 09-09-2010
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 12:56 PM.. Reason: Please use code tags
# 4  
Old 09-09-2010
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 01:07 PM..
This User Gave Thanks to Scott For This Post:
# 5  
Old 09-09-2010
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 02:12 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing double quotes in echo command

Please help me to use echo or printf type of command to print some value from variable within double quotes - I want to print the double quote ( " ") also. I tried #!/bin/bash VALUE=some_value echo '{"value" : "$VALUE"}' I was expecting the above script would produce .. {"value" :... (3 Replies)
Discussion started by: atanubanerji
3 Replies

2. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

3. Shell Programming and Scripting

How to pass two words within double quotes as variable?

Hi All, OS - Suse 10 ksh --version version sh (AT&T Research) 93s+ 2008-01-31 I am passing two words within double quotes ("Application Developer") to script as variable, but script is adding two single quotes between two words like ("Application' 'Developer"). below is simple test... (4 Replies)
Discussion started by: srimitta
4 Replies

4. Shell Programming and Scripting

How to pass parameter to pipe command row-wise?

Hi, I have a list of parameter in a file. I want to pass them one by one to piped command and syntax is like <command> <parameter> <command continues> How to achieve that ? Thanks (1 Reply)
Discussion started by: ezee
1 Replies

5. UNIX for Dummies Questions & Answers

Unable to send single and double quotes to command

Hi Unix experts, Believe me, this forum has been really great help and I searched for many things that were already answered before open new post that were just new versions of old one, but with this one, I just can't simply move any forward. This must be quite easy, but I cant find where I... (1 Reply)
Discussion started by: manolain
1 Replies

6. Shell Programming and Scripting

Pass command as a function parameter

Hi guys, can someome help with this question, I have defined a function that takes a command as a parameter, but when the command is executed from the function it will throw errors because what I believe is a special character escaping issue. I tried using the backslash to escape the pipe | and >... (2 Replies)
Discussion started by: marouanix
2 Replies

7. Shell Programming and Scripting

How to alias an awk command with single and double quotes?

Hi, I am trying to write the following command as an alias in my .bashrc file. bjobs -u all | awk '{if (NR > 1) {username++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username,i;}{print"\n Total Jobs=",NR-1,"\n" }}' The command simply puts how many jobs each user is... (2 Replies)
Discussion started by: jacekmaciek
2 Replies

8. Shell Programming and Scripting

ksh execute command containing double quotes

How do I execute a command containing a double quote ? I pass a variable to grep that contains spaces, so I need to quote it, but it does not work. #!/usr/bin/ksh set -x txt='"next to"' cmd="grep $txt ~dpearso5/file2" echo $cmd $cmd This is the error I get: + grep "next to"... (1 Reply)
Discussion started by: pearson05
1 Replies

9. Shell Programming and Scripting

unix command to insert double quotes

Hi, I am looking for a unix command which inserts double quotes around all values in a text file. For example, Input: 1234 200 4686 3506056 9646 457 5647 5066762 5656 366 5869 5978459 Output: "1234" "200" "4686" "3506056" "9646" "457" "5647" "5066762" "5656" "366" "5869"... (2 Replies)
Discussion started by: berlin_germany
2 Replies

10. AIX

how to pass variables surrounded in double quotes to awk?

Hi, I'm making progress on this but hung up on one last detail. I'd like to use AWK to pass the system date and time(among other things) to the first line of a file. Here's what I have: BEGIN {TOTALPP = 0;FREEPP=0;USEDPP=0;print "LPAR NAME:",lpar,"DATE:",tdate } I call AWK with the... (4 Replies)
Discussion started by: cruiser
4 Replies
Login or Register to Ask a Question