argument - vs --
on a command, if the argument "--" means end of options and only parse for regular arguments, then what can "-" mean?
|
Quote:
|
In traditional Unix a few tools took - to indicate the last option, others took - to indicate stdin.
Posix says that -- indicates the last option. Today the - should indicate stdin. But a few commands might still treat it as "last option" in order to be compatible with traditional Unix. |
so, basically, "-" would be an argument, not an option just as file names are arguments. but it would be up to the program to interpret the semantics, which for a program that is getting a bunch of file names there, would typically assume it to mean read STDIN for this data. but even if it allows the same file twice, it can only read STDIN once. of course, it could cache that data from the first "-" and read that cache for each subsequent "-" in its list of files. for programs meaning something other than a list of files, such as a list of users, it would have to give some particular meaning to "-" or flag it as an error.
i am currently developing a command line option/argument interpreter that will fit into a multi-layer interpreter for future commands i am writing which need some things other option parsers just don't seem to support. at the layer this new code is at it looks like "-" needs to be passed along as an argument. a lower layer will be dealing with understanding it as STDIN or whatever. |
Quote:
Quote:
|
Though EOF-condition on a terminal is not persistent, so theoretically something like this could work (untested):
Code:
cat - /etc/motd - >merged.txt |
In general the shell script will not evaluate/modify - and --, so they will be passed to the command as is.
The command itself will process these arguments and the interpretation depends only on the developers/designers. There are conventions, like - means stdin, -- means the last option, but again, it depends only on the command. Fortunately we have several different and conflicting conventions. So better to read the man page if you are unsure. As an interesting example see man startx. |
Quote:
Code:
$ seq 12|paste - - - |
... and as a bit of trivia,
Code:
# This logs you in as 'user', BUT you retain your orig env.... |
All times are GMT -5. The time now is 02:31 AM. |