ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
No, normally the argument "-" can only be used to replace one of the filenames in the commandline, because - as you said - you can only read stdin once, it is a pure queue, once read that part of the data is lost. And - of course - it is only of use in programs that have multiple file arguments. From "man diff"
Quote:
FILES are `FILE1 FILE2' or `DIR1 DIR2' or `DIR FILE...' or `FILE... DIR'.
If a FILE is `-', read standard input.
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.
# This logs you in as 'user', BUT you retain your orig env....
su user
# This logs you in as 'user', AND you get their env; iow exactly as if you had logged in as them from the start
su - user
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.