In the line of https://stackoverflow.com/questions/906590/echo-version-doesnt-works I need to know the version of echo
$ type -a echo | cut -d " " -f 3- | xargs -d '\n'
a shell builtin /usr/bin/echo /bin/echo
$ /usr/bin/echo -v
-v
$ /bin/echo -v
-v
In the line of https://stackoverflow.com/questions/906590/echo-version-doesnt-works I need to know the version of echo
$ type -a echo | cut -d " " -f 3- | xargs -d '\n'
a shell builtin /usr/bin/echo /bin/echo
$ /usr/bin/echo -v
-v
$ /bin/echo -v
-v
Standard echo doesn't take any options (or with XSI extensions, only recognizes the -n argument). In many cases, the echo you use is one built in to the shell, and in none of the shells I tested, the builtin echo recognizes --version. They do variously recognize at least -e, -E, -n though. The only echo I found that recognizes --version is the one from GNU coreutils, i.e. the one installed at /bin/echo on many Linux systems.
So, in most cases, the question of recognizing the version of echo comes down to recognizing the shell you're running. Or running /bin/echo, if you know you're on a system where that's GNU, and not e.g. Busybox. Also, as seen on the man page, the GNU coreutils version only supports --version, not -v or -V.
But in general, if you're trying to get something done, you don't need to depend on the particular version of something, just the supported functionality. And when looked at that way, it's easier to just use printf rather than echo.
If you want to print a string as-is, use
printf "%s\n" "$var"
If you want to process backslash-escapes in the string, use
printf "%b\n" "$var"
And if you want to skip the final newline, remove the \n from the first argument.
See Why is printf better than echo? and How do I print '-e' with echo?
Springboarding off @ilkkachu's answer:
On my macOS 10.15 laptop using zsh, I get the following:
% which echo
echo: shell built-in command
% whereis echo
/bin/echo
% /bin/echo --version
--version
Which is explained by referring to man echo: Apple packages a 2002 BSD version of echo in their new laptops - it supports only the -n argument. :)