The "echo" command does not recognize escape characters.

Posted on 2009-12-23
Last Modified: 2013-12-26
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"

I have a large number of scripts that will need reworked if I cannot force echo to behave right.  Suggestions?
Question by:motokent
    LVL 14

    Accepted Solution

    echo -e "\n\n\nTest\n\n"
    LVL 18

    Assisted Solution

    You need to use the -e option.

    When in doubt:
    man echo

    echo -e "foo\nbar"

    Open in new window


    Author Comment

    Is there a way to make the "-e" option the default?  (-e gets used without specifying it)
    LVL 18

    Assisted Solution

    You can create an alias before you run it.

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

    Open in new window

    LVL 14

    Assisted Solution

    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"

    LVL 14

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    After running Ubuntu some time, you will be asked to download updates for fixing bugs and security updates. All the packages you download replace the previous ones, except for the kernel, also called "linux-image". This is due to the fact that w…
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now