# Problems with irb? str = 'a\\b\\c' seems impossible

**URL:** <https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049>\
**Category:** Ruby\
**Created:** [May 19, 2006, 5:19pm UTC](https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049 "2006-05-19T17:19:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [May 19, 2006, 5:19pm UTC](https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049/1 "2006-05-19T17:19:30Z")

</div>

Can someone help me out with this, I can’t put the string ‘a\b\c’ in  
the variable str, which is strange, because I am working with the  
PickAxe book, and this what should work (page 71, 2nd ed.)

the two before seem to work, but the example in the book, ‘a\b\c’ seems  
not.  
This a bug? How come irb does not seem to understand the last quote?

irb(main):021:0\> str = ‘a\b\c ’  
=\> "a\b\c "  
irb(main):022:0\> str = ‘a\bc’  
=\> “a\bc”  
irb(main):023:0\> str = ‘a\b\c’  
irb(main):024:0’  
irb(main):025:0’ ’  
SyntaxError: compile error  
(irb):25: unterminated string meets end of file  
from (irb):25  
from :0

I’m very curious, 🙂  
Krekna

---

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [May 19, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049/2 "2006-05-19T17:47:43Z")

</div>

On Sat, May 20, 2006 at 12:19:10AM +0900, Krekna M. wrote:

> =\> “a\bc”  
> irb(main):023:0\> str = ‘a\b\c’  
> irb(main):024:0’  
> irb(main):025:0’ ’  
> SyntaxError: compile error  
> (irb):25: unterminated string meets end of file  
> from (irb):25  
> from :0

str=“a\b\c”

---

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [May 19, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049/3 "2006-05-19T17:54:00Z")

</div>

Hi –

On Sat, 20 May 2006, Krekna M. wrote:

> =\> “a\bc”  
> irb(main):023:0\> str = ‘a\b\c’  
> irb(main):024:0’  
> irb(main):025:0’ ’  
> SyntaxError: compile error  
> (irb):25: unterminated string meets end of file  
> from (irb):25  
> from :0

I’ve noticed that too. For some reason, ‘\c’ seems to produce  
something other than a literal backslash-c sequence. I stumbled on  
that a month or so ago but I don’t know why it happens.

(Helpful answer, isn’t it? 🙂

David

---

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [May 19, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049/4 "2006-05-19T18:14:01Z")

</div>

2006/5/19, Krekna M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> =\> “a\bc”  
> irb(main):023:0\> str = ‘a\b\c’  
> irb(main):024:0’  
> irb(main):025:0’ ’  
> SyntaxError: compile error  
> (irb):25: unterminated string meets end of file  
> from (irb):25  
> from :0

> > str = ‘a\b\c’  
> > =\> “a\b\c”  
> > puts str  
> > a\b\c  
> > =\> nil

Note that irb uses inspect - this is sometimes confusing as it will  
print a double backslash for a single backslash in the string.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [May 19, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049/5 "2006-05-19T18:00:45Z")

</div>

On 19-May-06, at 11:53 AM, removed\_email\_address@domain.invalid wrote:

> > This a bug? How come irb does not seem to understand the last quote?  
> > from (irb):25  
> > from :0
> 
> I’ve noticed that too. For some reason, ‘\c’ seems to produce  
> something other than a literal backslash-c sequence. I stumbled on  
> that a month or so ago but I don’t know why it happens.
> 
> (Helpful answer, isn’t it? 🙂

Idle speculation here. It looks like something is getting confused,  
in double quoted strings \c is the beginning of a control sequence

irb(main):004:0\> “\cX”  
=\> “\030”

and that may be mis-handled by irb?

Mike

–

Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.stok.ca/~mike/](http://www.stok.ca/~mike/)

The “`Stok’ disclaimers” apply.

---

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [May 19, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/problems-with-irb-str-a-b-c-seems-impossible/61049/6 "2006-05-19T18:26:24Z")

</div>

yes, \c seems to mean something itself, some more examples of strange  
behaviour below too.  
The last two examples seems to work, escaping ‘c’ two times.

irb(main):015:0\> str = “a\b\c”"  
=\> “a\010\002”  
irb(main):001:0\> str = 'a\b\c ’  
=\> “a\b\c "  
irb(main):002:0\> str = “a\b\c”  
irb(main):003:0”  
irb(main):004:0" "  
=\> “a\010\002\n\n”  
irb(main):005:0\> str = “a\b\d”  
=\> “a\010d”  
irb(main):006:0\> str = ‘a\b\d’  
=\> “a\b\d”  
irb(main):007:0\> str = “a\b\c”  
=\> “a\010\c”  
irb(main):008:0\> str = ‘a\b\c’  
=\> “a\b\c”

Krekna

2006/5/19, Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
