I wanted to create a file in my bash script using cat containing a TAB Char. However I couldn't manage to get it working. Here my tests:
Using plain tab:
cat >file.txt <<END
Text after plain tab.
END
Result:
Text after plain tab.
Using ^I:
cat >file.txt <<END
^IText after escaped I.
END
Result:
^IText after escaped I.
Using \033I:
cat >file.txt <<END
\033IText after another escaped I.
END
Result:
\033IText after another escaped I.
Thanks in advance :-)
There are three examples shown. The first works (perhaps some detail was omitted). The other two (a literal
"^I"and a literal"\033I") will not produce a tab becausecatdoes not do that. It does provide an option (-v) for going the other way, making the nonprinting characters displayable.As noted in another answer, the
echocommand can interpret some backslash sequences. For exampleThere are some differences between the varieties of
echoused on Linux as a standalone program (from coreutils) versus that which is part of the shell (perhapsbashordashorzsh). The POSIX standard is a good place to start.