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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
That’s the behavior of POSIX and UNIX conformant echo. With a UNIX conformant echo, you’d write:
echo 'Check Scriptc'
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 -en, so in that regard, bash and zsh are not POSIX conformant.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0