[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

script arg with doble quote

pere.noel

10/5/2006 3:19:00 PM

when i have a path like that :

/path/to/"Hello\ world"/

this string being the argument of a ruby script (the same does apply for
shell scripts) i don't get it right but rather :

/path/to/Hello world/

the doble quotes vanished due to shell.

i get this arg by the Finder (Mac OS X)

then, i can't change it because if the argument where single quotes
wrapped like that :

'/path/to/"Hello\ world"/'

i get the right arg, saying :

/path/to/"Hello world"/

someone sees a workaround ?


--
une bévue
6 Answers

Paul Lutus

10/5/2006 3:38:00 PM

0

Une bévue wrote:

> when i have a path like that :
>
> /path/to/"Hello\ world"/
>
> this string being the argument of a ruby script (the same does apply for
> shell scripts) i don't get it right but rather :
>
> /path/to/Hello world/
>
> the doble quotes vanished due to shell.
>
> i get this arg by the Finder (Mac OS X)
>
> then, i can't change it because if the argument where single quotes
> wrapped like that :
>
> '/path/to/"Hello\ world"/'
>
> i get the right arg, saying :
>
> /path/to/"Hello world"/
>
> someone sees a workaround ?

But you've just posted the solution -- single quote the argument.

When you post a problem and seek a solution, please make sure to state the
problem clearly, like this:

1. I wanted this: ________________________

2, But instead, I got this: _________________________

3. Here is how (2) differs from (1): _____________________

4. Here are the reasons I can't apply the obvious fix: _______________

--
Paul Lutus
http://www.ara...

pere.noel

10/5/2006 4:24:00 PM

0

Paul Lutus <nospam@nosite.zzz> wrote:

> But you've just posted the solution -- single quote the argument.

i can't the double quotes are eated by the shell and if i add the single
quote, it's to late
>
> When you post a problem and seek a solution, please make sure to state the
> problem clearly, like this:
>
> 1. I wanted this: ________________________

transform a unix path into an url provided the path is under the apache
server root.

/path/to/"Hello\ world!"/

>
> 2, But instead, I got this: _________________________

in case the path contains double quotes, the double quotes are eated by
the shell and or finder (mac os x). then i got :

/path/to/Hello\ world!/

>
> 3. Here is how (2) differs from (1): _____________________

the " vanished.
>
> 4. Here are the reasons I can't apply the obvious fix: _______________

the obvious fix being to wrapp the path with single quote like that :

'/path/to/"Hello\ world!"/'

this would protect the double quote, unfortunately at the time i can add
single quotes (within a shell script or a ruby one) it is too late
because double quote vanished due (i believe) to the shell way of
passing arf to any kind of scripting facility (zsh, sed, ruby)...
--
une bévue

Paul Lutus

10/5/2006 5:21:00 PM

0

Une bévue wrote:

/ ...

> this would protect the double quote, unfortunately at the time i can add
> single quotes (within a shell script or a ruby one) it is too late
> because double quote vanished due (i believe) to the shell way of
> passing arf to any kind of scripting facility (zsh, sed, ruby)...

If I understand you correctly, you don't have control over where the shell
script argument comes from, and at the first opportunity, it's already too
late -- essential data has already been lost. Yes?

Is there any way to access the original data that gets around this problem?
Can you tell a user to act differently? You haven't said where the
information comes from, or how it gets to your script.

--
Paul Lutus
http://www.ara...

Justin Collins

10/6/2006 9:37:00 AM

0

Une bévue wrote:
> Paul Lutus <nospam@nosite.zzz> wrote:
>
>> But you've just posted the solution -- single quote the argument.
>
> i can't the double quotes are eated by the shell and if i add the single
> quote, it's to late
>> When you post a problem and seek a solution, please make sure to state the
>> problem clearly, like this:
>>
>> 1. I wanted this: ________________________
>
> transform a unix path into an url provided the path is under the apache
> server root.
>
> /path/to/"Hello\ world!"/
>
>> 2, But instead, I got this: _________________________
>
> in case the path contains double quotes, the double quotes are eated by
> the shell and or finder (mac os x). then i got :
>
> /path/to/Hello\ world!/
>
>> 3. Here is how (2) differs from (1): _____________________
>
> the " vanished.

Why do you need the double quotes? If it's to pass the path back to the shell (or other, similar place), you can put quotes around the entire argument to the same effect.

For example:

path = ARGV[0]
system("ls -l '#{ARGV[0]}'") #Using single quotes avoids having to escape them


Does that help?

-Justin

pere.noel

10/6/2006 11:36:00 AM

0

Collins, Justin <collinsj@seattleu.edu> wrote:

>
> Why do you need the double quotes? If it's to pass the path back
> to the shell (or other, similar place), you can put quotes
> around the entire argument to the same effect.
>
> For example:
>
> path = ARGV[0]
> system("ls -l '#{ARGV[0]}'") #Using single quotes avoids having
> to escape them
>
>
> Does that help?

no because the path I get is trhu another api i'm not the master of.

in fact it is my lone arg coming from Finder (Mac OS X) thru (Bog Cat a
Contextual Menu helper).

i think big cat is buggy for that point of view then, for the time being
i prevent the final user not to use double quotes in file/dir names
which pretty uncommon )))

--
une bévue

Tim Hunter

10/6/2006 11:50:00 AM

0

Une bévue wrote:
> when i have a path like that :
>
> /path/to/"Hello\ world"/
>
> this string being the argument of a ruby script (the same does apply for
> shell scripts) i don't get it right but rather :
>
> /path/to/Hello world/
>
> the doble quotes vanished due to shell.
>
> i get this arg by the Finder (Mac OS X)
>
> then, i can't change it because if the argument where single quotes
> wrapped like that :
>
> '/path/to/"Hello\ world"/'
>
> i get the right arg, saying :
>
> /path/to/"Hello world"/
>
> someone sees a workaround ?
>
>
>
Just escape the double quotes the same way you escape the blank:

\"Hello,\ world\"