'|' means in programming 'or' so the result would be.
if "abc" is true which it is then command line will not see
ruby -e 'puts gets.chomp("c")'
···
----- Original Message -----
From: "Peter Zotov" <whitequark@whitequark.org>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Friday, April 15, 2011 7:21:24 PM
Subject: Re: chomp behaviour
On Sat, 16 Apr 2011 11:08:10 +0900, Steel Steel wrote:
Using 1.9.1
I noticed something with chomp
$ echo "abc" | ruby -e 'puts gets.chomp("c")'
abc
$ irb
irb(main):001:0> "abc".chomp("c")
=> "ab"
It doesn't work on the command line, or am i doing it wrong.?
comments?
"gets" returns the whole read string, with trailing newline ("\n").
Try: echo "abc" | ruby -e 'p gets' # => "abc\n"
You can either chomp it twice, or do "echo -n" instead of "echo"
(the former does not add a newline), or use "strip" method, which
removes all whitespace from begin and end of a string (check also
"rstrip" and "lstrip" functions).
--
WBR, Peter Zotov.
You are obviously not a *nix user ;]
That is a pipe, not a logical or.
···
On 22/04/11 10:57, JOSEPHJONES3247 wrote:
'|' means in programming 'or' so the result would be.
if "abc" is true which it is then command line will not see
ruby -e 'puts gets.chomp("c")'
----- Original Message -----
From: "Peter Zotov"<whitequark@whitequark.org>
To: "ruby-talk ML"<ruby-talk@ruby-lang.org>
Sent: Friday, April 15, 2011 7:21:24 PM
Subject: Re: chomp behaviour
On Sat, 16 Apr 2011 11:08:10 +0900, Steel Steel wrote:
Using 1.9.1
I noticed something with chomp
$ echo "abc" | ruby -e 'puts gets.chomp("c")'
abc
$ irb
irb(main):001:0> "abc".chomp("c")
=> "ab"
It doesn't work on the command line, or am i doing it wrong.?
comments?
"gets" returns the whole read string, with trailing newline ("\n").
Try: echo "abc" | ruby -e 'p gets' # => "abc\n"
You can either chomp it twice, or do "echo -n" instead of "echo"
(the former does not add a newline), or use "strip" method, which
removes all whitespace from begin and end of a string (check also
"rstrip" and "lstrip" functions).