Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
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
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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