DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 27th September 2011
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,070
Thanked 198 Times in 156 Posts
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
 

Tags
/bin/sh, bourne shell, quotes

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
three problems :) craze OpenBSD Packages and Ports 6 6th March 2011 03:26 PM
GDM Problems Saint OpenBSD Packages and Ports 4 29th August 2010 09:42 AM
startup (rc) problems kopcicle OpenBSD General 9 15th May 2010 08:35 PM
GCC causing problems it seems. Marred FreeBSD Ports and Packages 12 11th September 2008 08:11 AM
ATI DRI problems harisman FreeBSD General 16 11th May 2008 05:12 PM


All times are GMT. The time now is 05:41 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick