Feedback

type to search

How to represent strings with control characters (like \n \t) in bash?

Asked by

How to represent strings with control characters (like \n \t) in bash?

or Cancel

2 answers

0

belkka

Solution that I found in “man 1 bash” (section QUOTING):


$‘hello\nworld’

echo \$‘hello\nworld’ == echo -e ‘hello\nworld’ == printf ‘hello\nworld’
or Cancel
0

sumpfralle

Storing and handling these characters does not need any special care:

  TEXT=“foo\nbar”

Just printing it might feel complicated. “printf” is a good solution for this:

  printf “foo\nbar”

Another alternative is “echo -e” – but it is not portable.

or Cancel

Your answer

You need to join Debian to complete this action, click here to do so.