Apparently < and | behave similarly
There are slight similarities, but you can't take that too far. They both represent redirection.
<
redirects the standard input stream (stdin
) of the command on the left to refer to the file on the right. The command will run in its own process only if it is an external program (like wc
).
|
redirects the standard output stream (stdout
) of the command on the left to the standard input stream (stdin
) of the command on the right. The mechanism used is called an anonymous pipe, and both commands run in their own child process.
<
and |
are not commands, they are part of shell grammar, so there won't be any man
pages for them. As part of the bash
language you have to use man bash
then search for REDIRECTION
(for <
) or Pipelines
(for |
).
Section 1 man
pages are for programs, not one specific language like a shell, section 2 is for kernel APIs called from C, etc. So don't expect details of your specific shell to appear as separate man pages. So there is a man bash
, man sh
, man csh
, man zsh
, etc.
Surprisingly, [
is a shell builtin:
$ type [
[ is a shell builtin
and is also known as test
. But:
$ type [[
[[ is a shell keyword
[
, test
, [[
are all commands and additional documentation is available in bash
using help
, e.g.
$ help [
So how do you know if the symbol is a command or part of the grammar? By learning the language, there is no other way. Follow tutorials, read man bash
, look at examples, but above all experiment yourself and try things out.
It is not easy for a beginner, but you should remember that shell syntax was written for programmers to use and understand, it was never designed for end-users.
You remark (complain?) that the same character is used for different meanings. That is common within programming languages. For example, in C *
is used to qualify a declaration of a pointer, as a multiplication binary operator, as half a comment symbol, and as a unary operator to dereference a pointer. There are many other multi-use characters in various languages. This is partly because early keyboards were only capable of the printable part of the 128 character ASCII set. Attempts at using Unicode operators (e.g. Perl 6) have not been widely adopted.