From: Rick DeNatale Date: 2007-12-18T01:05:37+09:00 Subject: Re: Backslashes in Command Line Arguments On 12/16/07, Joseph Pecoraro wrote: > In writing a script that takes strings on the command line I have run > into a small problem which I don't see any way around. Here is a very > simplified program that just prints out the first command line argument, > and using p you can see exactly what is in the string. > > [example.rb] > p $*[0] > > > Now when I send some different (but similar) strings I end up with the > same result in the ARGV array: > > $ ruby example.rb "\a" > "\\a" > > $ ruby example.rb "\\a" > "\\a" > > $ ruby example.rb \\\a > "\\a" > > 1) Is this because I am running in bash and the shell maps the \\ into a > single backslash? No, it's because you are using p instead of puts. The p method prints the result of sending the inspect message to its argument, and String#inspect produces a what ruby string literal to represent the string looks like, and since \ is the escape character in ruby string literals it needs to be escaped itself in the output of inspect. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/