View Single Post
  #1   (View Single Post)  
Old 27th September 2011
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default /bin/sh quoting problems

Can anyone explain to me why this doesn't work?

Code:
#!/bin/sh

#PS4=">>>> "
#set -xv

var="'This is label'"
ls  ${var}

[~/]% ./test.sh
ls: cannot access 'This: No such file or directory
ls: cannot access is: No such file or directory
ls: cannot access label': No such file or directory
From commandline (/bin/sh):
Code:
sh-4.2$ ls 'This is label'
This is label
I'm confused ... ... Turning on set -xv only served to increase my confusion

Code:
[~]% ./test.sh

var="'This is label'"
>>>> var=''\''This is label'\'''
ls  ${var}
>>>> ls ''\''This' is 'label'\'''
ls: cannot access 'This: No such file or directory
ls: cannot access is: No such file or directory
ls: cannot access label': No such file or directory
Exit 2
Where did all those quotes come from ?

The larger picture:

I want to build a variable with arguments for (c)dialog, i.e.:
# dialog --menu 'Hello world' 10 40 9 "This is Label" "This is text "

If I put "This is label" "This is text" inside a variable it doesn't work ...

(Of course, the real script has many more menu entries... )
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.

Last edited by Carpetsmoker; 27th September 2011 at 03:32 PM.
Reply With Quote