print new line bash code example

Example 1: echo with new lines bash

# Using echo
echo -e "Line 1\nLine 2"
echo "Line 1 $HOME expanded
Line 2"
echo 'Line 1 $HOME not expanded
Line 2'

# Similar result, using cat
cat <<EOF
Line 1 $HOME expanded
Line 2
EOF
cat <<'EOF'
Line 1 $HOME not expanded
Line 2
EOF

Example 2: echo new line

echo -e "hello\nworld"

Example 3: newline in echo unix

echo $'hello\nworld'

Example 4: echo new line in a file bash

echo -e "Line 1\nLine 2"

Example 5: echo new line

echo -e "hello\nworld"
# Output
  /*
   * hello
   * world
   */

Example 6: how to print new line in shell script

echo -e 'This is First Line \nThis is Second Line'

Tags:

Php Example