When we need to use escape sequence characters with echo command we must use the -e option. Like

echo -e "Enter your name : \c"

But when we include such kind of statements inside a shell program (.sh file), it produces a mysterious error. It prints

-e Enter your name : 

It doesn't need that -e option with echo command as if we write like this

echo "Enter your name : \c"

It shows output with no errors, but that doesn't work in shell.

So what is the reason? I am using bash shell and Ubuntu 15.04 version.


I guess you haven't used a shebang (#! /bin/bash as the first line of your script). In that case, the script is run using /bin/sh, which is /bin/dash. And echo in dash doesn't support the non-standard -e (have a look at the POSIX standard). You really shouldn't use echo -e. Use printf instead for far more portable behaviour. See Why is printf better than echo`? on Unix and Linux. The following commands should behave identically:

bash -c 'printf "%s" "Enter your name"'
dash -c 'printf "%s" "Enter your name"'
  • 3
    +1. echo is notoriously non-portable. – glenn jackman Jan 1 '16 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.