# Script arg with doble quote

**URL:** <https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149>\
**Category:** Ruby\
**Created:** [October 5, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149 "2006-10-05T17:21:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 5, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149/1 "2006-10-05T17:21:03Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 5, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149/2 "2006-10-05T17:41:05Z")

</div>

Une bÃ©vue wrote:

> 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: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

1. Here is how (2) differs from (1): \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

2. Here are the reasons I can’t apply the obvious fix: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 5, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149/3 "2006-10-05T18:27:10Z")

</div>

Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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!/

> 1. Here is how (2) differs from (1): \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

the " vanished.

> 1. 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)…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 5, 2006, 7:25pm UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149/4 "2006-10-05T19:25:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 6, 2006, 11:38am UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149/5 "2006-10-06T11:38:59Z")

</div>

Une bÃ©vue wrote:

> /path/to/Hello\ world!/
> 
> > 1. 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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 6, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149/6 "2006-10-06T13:41:12Z")

</div>

Collins, Justin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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 )))

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 6, 2006, 1:51pm UTC](https://www.ruby-forum.com/t/script-arg-with-doble-quote/71149/7 "2006-10-06T13:51:14Z")

</div>

Une bévue wrote:

> someone sees a workaround ?

Just escape the double quotes the same way you escape the blank:

“Hello,\ world”
