If you want to print the output as given, you just need to:
foo='Hello \ World!' bar=$(tr -d '\\' <<<"$foo") echo $bar
Hello World!
If you want to compress spaces, as they are stored in a variable, then one of:
bar=$(tr -d '\\' <<<"$foo" | tr -s '[:space:]' " ") bar=$(perl -0777 -pe 's/\\$//mg; s/\s+/ /g' <<<"$foo")
The advantage of the perl version is that it only removes backtraces of the line continuation (at the end of the line).
Note that when you use double quotes, the shell takes care of the continuation of the line (correct, without spaces after the slash:
$ foo="Hello \ World" $ echo "$foo" Hello World
So, at this point it is too late.
If you use single quotation marks, the shell will not interpret line extensions, but
$ foo='Hello \ World! here we are' $ echo "$foo" Hello \ World! here we are $ echo "$foo" | perl -0777 -pe 's/(\s*\\\s*\n\s*)/ /sg' Hello World! here we are
source share