3 ms·
It makes relying on meaningful options passed to `echo` non-portable. You can always rely on `echo` being on the system (thanks to POSIX), which is what makes i
by uplime 5y ago
It makes relying on meaningful options passed to `echo` non-portable. You can always rely on `echo` being on the system (thanks to POSIX), which is what makes it portable. Relying on the behavior of -e/-n/etc is not.
- kevincox 5y agoBut that is my point. Print the string "-e\n" in a portable way. I can't think of a way. For GNU coreutils you would need to do `echo - -e` but on a complaint echo you would need to do `echo -e`. So maybe it is portable for some strings. But it can't be used for all cases. Even something as simple as outputting a user entered string can't be done because you don't know if it is handled specially.
- uplime 5y agoYou can with the POSIXLY_CORRECT environment variable: $ /bin/echo --version echo (GNU coreutils) 8.30 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Brian Fox and Chet Ramey. $ POSIXLY_CORRECT=1 /bin/echo -e -e Which is why I say relying on `echo` is fine, since its standard. Relying on `echo` to use options is not. That's also why the author is correct that you should use `printf`, because POSIXLY_CORRECT is not set, then you can run into non-standard behavior, like you showed.