Take the 2-minute tour ×  How can I enter the following contents
in a file:   I tried using echo "Hi\nabcd" >> ab.txt, but in the
file it's written as is (the \n is included, instead of a
newline)  share|improve this question  4 Answers 4  You need to
tell echo to honor escape sequences.  echo -e "Hi\nabcd" >>
ab.txt share|improve this answer thanks ..thats what I was
looking for ... –  Novice User Apr 2 '12 at 15:44  The behavior
of echo varies from shell to shell¹; printf's behavior is more
standard.  printf "Hi\nabcd" >> ab.txt  ¹ "It is not possible to
use echo portably across all POSIX systems unless both -n (as
the first argument) and escape sequences are omitted."
share|improve this answer Best answer, IMO. –  jw013 Apr 2 '12
at 17:56 Yup. I've been bitten when echo's behavior changed in a
system update, and some of my scripts broke... –  Gordon
Davisson Apr 2 '12 at 22:59 type printf printf is a shell
builtin - it's the same situation as with echo: in bash it is a
builtin. –  user unknown Apr 3 '12 a