chomp for bash

Bash doesn’t have chomp command but you can use tr to get rid of \n \r (and other) characters.

Comments

  1. realtebo Hei ! This simple post helpd me so much ! Thanx, i was blocked at writing a bash single-line command because I cannot eliminate spaces beetween two strings... whit tr -t [:space:] i resolved !

    Comment by realtebo — 04.03.2009 @ 01:22

  2. flipouk Thanks for the tip. Excellent!

    Comment by flipouk — 21.07.2009 @ 14:52

  3. Ed Greenberg Helped me too. I had a curl that returned a single line, but curl adds a linefeed that I didn't need. It's easy to deal with in perl, but I'm working in shell today. A=`curl http://foo` B=`echo $A|tr -d \\n` Thanks.

    Comment by Ed Greenberg — 05.02.2010 @ 18:39

  4. Ganneff A little late, but why not simply use bash itself for this? It is powerful enough, no need to have an external tool called: var1="something with space and linefeeds" var1=${var1// /_} echo $var1 (I only used _ to make it more visible here)

    Comment by Ganneff — 23.04.2010 @ 16:33

comments powered by Disqus