Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I tried 'man echo' in Bash and it told me that 'echo --help' will display help then exit, and similarly, that 'echo --version' will output version and exit. But why it doesn't work ? 'echo --help' just simply prints '--help' literally.

share|improve this question
2  
Note that production of a help message by echo --help is a bug. Imagine what happens if you do: printf "The option you entered is: " ; echo "$opt" and the shell variable opt happens to be contain the text --help. Per the POSIX standard, echo is not permitted to behave in this way, but the GNU echo is obnoxiously non-conforming. –  R.. Sep 5 at 5:23
    
@R.. So echo -e and echo -n is also a bug, by your logic? –  Tyilo Sep 10 at 21:44
    
@Tyilo: See the specification in POSIX, or my coverage of the issue here: etalabs.net/sh_tricks.html –  R.. Sep 10 at 22:04
    
@R.. Imagine what happens if you do: printf "The option you entered is: " ; echo "$opt" and the shell variable opt happens to be contain the text -e or -n. –  Tyilo Sep 11 at 8:58
    
@Tyilo: Rather than re-explaining it I liked to a page where I already explained the answer to that question. –  R.. Sep 11 at 13:17

3 Answers 3

up vote 19 down vote accepted

man echo relates to the echo program. GNU echo supports a --help option, as do some others. When you run echo in Bash you instead get its builtin echo which doesn't.

To access the echo program, rather than the builtin, you can either give a path to it:

/bin/echo --help

or use Bash's enable command to disable the built-in version:

$ enable -n echo
$ echo --help

Bash has built-in versions of a lot of basic commands, because it's a little faster to do that, but you can always bypass them like this when you need to.

share|improve this answer
    
Serves me right for using zsh. enable does work, though. –  Michael Homer Sep 4 at 3:39
    
@MichaelHomer So some built-in version may differ from... original ones ? If there are differences, then what's the name for all original commands, including 'echo program' as you mentioned ? Or what term do we use to distinguish them from built-in versions ? –  booksee Sep 4 at 3:50
1  
@booksee: Yes, they can differ. GNU echo in particular has a lot of extensions above POSIX, and Bash's echo only a few. There isn't really a general name that I can think of for commands that could be shadowed by builtins. There aren't so many that you'd need one: echo, test, [, and pwd are the ones you're likely to encounter. –  Michael Homer Sep 4 at 3:56
    
@Gnouc: Yes, command explicitly does call builtins always. I don't know what I was thinking, other than that zsh's works the other way. –  Michael Homer Sep 4 at 3:58
2  
"use Bash's enable command to disable" yup, guys, is like that –  Braiam Sep 4 at 4:00

In addition to other answers, you can use

$ help echo

too see a brief help for built-in echo command.

share|improve this answer

You are using the echo built-in command of bash, which does not understand the --help option. Use:

/bin/echo --help

To see the help for the built-in echo, use man bash and search for echo.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.