Get rid of newline from shell commands in Ruby

I am trying to run simple shell commands in my script, but am unable to
get rid of new lines even using chomp or chop.

Is there something I am missing ?

  u=`echo  '#{l}' | cut -d: -f4`.chop()
  p2=`echo '#{l}' | cut -d: -f3`.chop()
  p1=`echo '#{l}' | cut -d: -f2`.chomp()
  h=`echo  '#{l}' | cut -d: -f1`.chop()

Cant get newlines to go !! ??

  path="#{p1}/#{@CODELINEFILTER}#{p2}"
  puts path

Any suggestions ?

On Sep 23, 2011, at 2:36 PM, Pavan ā€¦ wrote:

Cant get newlines to go !! ??

 path="#{p1}/#{@CODELINEFILTER}#{p2}"
 puts path

Any suggestions ?

You might try using

echo -n

and sidestep the problem completely.

Dan N.

On Sat, 24 Sep 2011 04:03:59 +0900, Dan N. wrote:

 p1=`echo '#{l}' | cut -d: -f2`.chomp()

You might try using

echo -n

and sidestep the problem completely.

Dan N.

Iā€™m somewhat confused as to why a more rubish construct like:

u,p2,p1,h = l.split(ā€™:ā€™)

is not more appropriate?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs