2

I have an echo statement in my script as below:

echo -ne "Check Script";

I was expecting it to print

Check Script

but I am getting the below output

-ne Check Script

But when I run the same script on some other machine I get the expected output. What could be machine specific variables or properties because of which the script is behaving differently.

  • 1
    The operating system, the shell, and the value of shopt xpg_echo. – Mikel Nov 7 '12 at 16:26
  • @Mikel: Red Hat Enterprise Linux Server release 5.7 (Tikanga). Using kshell. shopt xpg_echo didn't work for me.I got error -ksh: shopt: not found [No such file or directory] – g4ur4v Nov 7 '12 at 19:39
7

That's the behavior of POSIX and UNIX conformant echo. With a UNIX conformant echo, you'd write:

echo 'Check Script\c'

Best is not to use echo but printf instead which has fewer portability issues.

printf %s 'Check Script'

Note that POSIX allows -n as an extension (but with unspecified behavior). echo -e is meant to output -e\n, so in that regard, bash and zsh are not POSIX conformant.

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.