replace newline character in bash variable? replace newline character in bash variable? bash bash

replace newline character in bash variable?


Yes you are right, it removes the newline character. I think the purpose of the test is to make sure $dir doesn't contain multiple lines.

Alternatively, you can remove \newline by

${dir/$'\n'/}

This doesn't require two lines so I think it looks better.