[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

The "echo" command does not recognize escape characters.

I recently installed Ubuntu on a new server.  Users shell is bash.  Echo does not support simple escape characters.  Example:
clwrdata$ echo "\n\n\nTest\n\n"
\n\n\nTest\n\n

I have a large number of scripts that will need reworked if I cannot force echo to behave right.  Suggestions?
0
motokent
Asked:
motokent
  • 3
  • 2
4 Solutions
 
Fabio MarzoccaFreelancerCommented:
echo -e "\n\n\nTest\n\n"
0
 
MorcalavinCommented:
You need to use the -e option.

When in doubt:
man echo

echo -e "foo\nbar"

Open in new window

0
 
motokentAuthor Commented:
Is there a way to make the "-e" option the default?  (-e gets used without specifying it)
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
MorcalavinCommented:
You can create an alias before you run it.

$ alias echo="echo -e"
$ echo "foo\nbar"

Open in new window

0
 
Fabio MarzoccaFreelancerCommented:
You can add in user's .bashrc (or in global /etc/bashrc) the following ine:

alias myecho='echo -e'

then just type in your script:

myecho  "\n\n\nTest\n\n"

0
 
Fabio MarzoccaFreelancerCommented:
It is not recommended to alis the command "echo" as it is used everywhere in other scripts
If you need to alis it, change the name.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now