GithubHelp home page GithubHelp logo

echo is missing the -e option about ekam HOT 4 CLOSED

capnproto avatar capnproto commented on June 3, 2024
echo is missing the -e option

from ekam.

Comments (4)

kentonv avatar kentonv commented on June 3, 2024

Do you observe the output being incorrect on your machine? If so, what distro?

-e is actually a non-standard option implemented by Bash. make invokes /bin/sh which on Debian-derived distros is actually Dash, not Bash. Dash's echo does not support -e (it will literally print -e if you try to pass this flag), but it interprets escapes by default (POSIX unhelpfully leaves it implementation-defined whether escapes are interpreted by default). So using -e here would actually produce incorrect output, whereas currently it is correct (on my machine).

Weirdly, on OSX, where /bin/sh is actually Bash, when invoked as sh it exhibits Dash-like behavior in this respect, but on Debian if I symlink /bin/sh to bash I get Bash behavior even when invoked as sh. So I suppose if you're using a distro where /bin/sh is Bash, you might see the wrong output?

Sadly, using /bin/echo won't solve this problem as on some platforms (OSX) it does not implement -e either.

So -e definitely won't work, but my current solution works on all machines I own. If it doesn't work on yours, maybe I just need to write multiple echo statements.

from ekam.

ryanmjacobs avatar ryanmjacobs commented on June 3, 2024

I'm running Arch Linux which has its /bin/sh symlinked to bash. And you're right, it looks like -e is a BASH-specific option. On a Ubuntu system running /bin/sh symlinked to dash, it works without the -e option.

Supposedly, running bash with the program name sh will cause it to use set -o posix to enable more posix-like features. But alas, this still doesn't fix echo's behavior across all systems.

There are threes ways I think this could be fixed:
a) Break up the echo into multiple calls.
b) Use printf instead, e.g. printf "=====\nsomething\n===== works fine
c) Detect what shell is running with sh --version, then set a variable ECHO to either echo or echo -e and use `$(ECHO) "====\nsomething\n===="

Honestly, I don't think it's worth the effort but if you really wanted it to look the same on all systems, I would go with printf. That would require minimal changes.

from ekam.

kentonv avatar kentonv commented on June 3, 2024

Oh, duh, printf! I actually figured this out once before and then forgot -- the Sandstorm Makefile only uses printf for exactly this reason. Durr. Thanks for the reminder.

from ekam.

ryanmjacobs avatar ryanmjacobs commented on June 3, 2024

Ahh, no problem. 😬

from ekam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.