I use both man and --help in Bash programming to get help.
For example, to get information about usage of ls command, I may use
man ls
Or
ls --help
Both give some what similar output. What is the difference between these two?
For one, --help is not a command, it is an argument that is often given to a command to get help using it. Meanwhile, man is a command, short for "manual". Manual pages are installed by many programs, and are a common way to find help about commands, as well as system calls, (e.g. fork()).
If a program installs a manual page, it can always be accessed via the man command, whereas --help is just a common convention, but need not be enforced—it could be just (and only) -h.
man also typically uses a pager, such as less, automatically, which can make viewing and searching through the information much easier.
Finally, you mention Bash programming in your question—none of this is unique to Bash. Bash doesn't care about the commands themselves or their arguments for the most part.
man will show you for ls you can type man -w ls
man man, but when I do, I always learn new stuff from it :)
man man.
man foo|grep '^[A-Z]' (for that I don't know the command line switch that does it directly too)? or maybe man -wa foo?
In most scenarios man is more detailed than --help. help gives the command line options for a particular command. But man is a lot more detailed.
Plus man is a command-line tool in itself whereas --help is a command-line arg for a tool. Small difference.
In the first you asking the system to search the manual pages for help on the command. The second you are asking the command to provide its own help. The two will most certainly differ - usually the command provides a reminder of its options where as the man page is a detailed description.
--help you know that you are getting the help message from the program that you want to run. Man pages can get out of sync with /bin and so can refer to software versions different from what's actually installed.
man some_command is something you can expect to work on all Unix and Unix like OSes, unless the manual pages are not installed.
some_command --help is mostly a GNUism so it generally won't work with non GNU implementations.
GNU, which doesn't like manual pages for some reason, also introduced info some_command as third alternative.
I find --help useful as it lets me call help up while I'm modding a command
For example
rsync -vPn ./* ./newfolder/.
Oh -- What is the flag for compress?
rsync -vPn --help ./* ./newfolder/. | less
I find the help command on flags sometimes very very useful and less time consuming. With man I've got to type it in and the go back through my history to get back to the command I was in.