In BASH, How do i replace \r from a variable that exist in a file written using HTML <textarea></textarea>

user285594 picture user285594 · Oct 18, 2011 · Viewed 21.9k times · Source

How do i replace the \r?

#!/bin/bash
...

# setup
if [[ $i =~ $screen ]]; then

    ORIGINAL=${BASH_REMATCH[1]}          # original value is: 3DROTATE\r
    AFTER   =${ORIGINAL/\\r/}            # does not replace \r
    myThirdPartyApplication -o $replvar  # FAILS because of \r

fi

Answer

tharrrk picture tharrrk · Apr 25, 2013

This should remove the first \r.

AFTER="${ORIGINAL/$'\r'/}"

If you need to remove all of them use ${ORIGINAL//$'\r'/}