4 ms·
Yet another way to do this is to use "/bin/echo" instead of the builtins or printf. "/bin/echo" is part of POSIX.
by KC8ZKF 15y ago
Yet another way to do this is to use "/bin/echo" instead of the builtins or printf. "/bin/echo" is part of POSIX.
- BrandonM 15y agoThat is true, but there are two caveats: 1. POSIX /bin/echo does not recognize any options other than "-n", and "-n" is "implementation-defined". [0] So you end up right back at the same problem. 2. I highly recommend using built-ins where possible. Invoking /bin/echo instead of using echo involves copying a string into an argument vector, setting argc, loading /bin/echo, attaching std file descriptors, and forking. All of this to print a string to stdout. It's much better to explicitly specify the behavior you want by invoking the appropriate interpreter, or to use /bin/sh while being sure to stick to POSIX-compliant functionality (e.g. printf). [0] http://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html http://pubs.opengroup.org/onlinepubs/009695399/utilities/ech...
- dfox 15y agoPOSIX specified way to get results you are expecting is "command -p echo", as POSIX does not guarantee where the utilities are located, on the other hand it guarantees that all utilities that are implemented as shell builtins while they don't need to (eg. cd makes sense only as builtin) must also be present on filesystem.