It is currently Thu, 20 Jan 2022 04:34:01 GMT

Author Message
 double quote variable expansion

I'm trying to pass a string containing spaces to an external program
(dialog) from a shell script.  Hopefully I can explain this well enough
so you don't need to know the 'dialog' program.  Basically, I present a
menu with 2 or 3 options.  The third option may or may not be available
depending on the value of $OPT3.  If it is not available, I don't want
to put it in the menu.  The problem I am running into is how to pass the
10th and 11th options to the external program.  See code below:


MSG3="Third option"

dialog --menu "Menu" 10 60 5 \
         "One" "First option" \
         "Two" "Second option" \
         ${OPT3+`echo "Three" \""$MSG3"\"`}

echo done

When I run with -x, I get the following:
$ sh -x /tmp/
+ MSG3=Third option
++ echo Three '"Third option"'
+ dialog --menu Menu 10 60 5 One 'First option' Two 'Second option'
Three '"Third' 'option"'

Error: Expected 2 arguments, found only 1.
Use --help to list options.

+ echo done

I understand why the error occurs (the output from 'dialog').  I would
like to understand how I can cause the script to execute dialog like so:

+ dialog --menu Menu 10 60 5 One 'First option' Two 'Second option'
Three 'Third option'

Can someone please enlighten me on this?


 Sat, 04 Oct 2008 05:06:22 GMT   
 double quote variable expansion
On 2006-04-17, Jason Roscoe wrote:

         ${OPT3+"Three" "$MSG3"}

- Show quoted text -

   Chris F.A. Johnson, author   |    <>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence

 Sat, 04 Oct 2008 05:21:44 GMT   
 double quote variable expansion
That works.  Thanks Chris.  That must be the only thing I didn't already

 Sat, 04 Oct 2008 05:31:31 GMT   
   [ 3 post ] 

Similar Threads

1. Double quotes within double quotes (no apostrophes)

2. HELP! Double variable expansion question

3. variable and double quotes

4. executing a value of a variable with double-quotes

5. ? about single quote-double quote

6. replace single quote to double quote with an example

7. replace single quote to double quote with an example

8. Problem in sed using double quotes and single quotes

9. use of quotes in assignment of variable to variable

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software