Showing posts with label Shell scripting echo new line to file. Show all posts
Showing posts with label Shell scripting echo new line to file. Show all posts

Monday, 24 September 2018

shell script echo new line to file

var1="Hello"

var2="World!"
logwrite="$var1\n$var2"
echo -e "$logwrite"  >> /Users/username/Desktop/user.txt
Explanation:
The \n escape sequence indicates a line feed. Passing the -e argument to echo enables interpretation of escape sequences.
It may even be simplified further:
var1="Hello"
var2="World!"
echo -e "$var1\n$var2"  >> /Users/username/Desktop/user.txt
or even:
echo -e "Hello\nWorld! "  >> /Users/username/Desktop/user.txt