I see the - operator behaving in different ways with different commands.
For example,
cd -
cds to the previous directory, whereas,
vim -
reads from stdin
So I want to know why the - operator is behaving in 2 different ways here. Can someone point me to some detailed documentation of the - operator?
It is not an operator, it is an argument. When you write a program in C or C++ it comes as
argv[1](when it is the first argument) and you can do whatever you like with it.By convention, many programs use
-as a placeholder for stdin where an input file name is normally required, and stdout where an output file name is expected. Butcddoes not require reading a file stream, why should it need stdin or stdout?Extra: here below is the excerpt from vim’s
main.cthat parses arguments that begin with-: if there is no additional character it activates STDIN input.