what is the function of this operator "-" in linux
Dear Linux Experts,
I'm New to linux, I'm keen to understand and learn Linux OS, Shell scripting , Can you let me what is function of this operator " - " in linux. example: $cut -d \| -f 1,4- file_name1 | paste -d \| file_name2 - $cut -d \| -f 1,4- file_name1 | paste -d \| - file_name2 Pls explain me its role, Kindly add cc to "pasha@yashasvi.co.in" |
Welcome to LQ!!
Quote:
I STRONGLY RECOMMEND that you remove your e-mail address above---you are inviting a SPAM attack. In the examples you show, "-" is not really an "operator" it is a flag to tell the utility that the next character(s) are option specifiers. Look at the man page for just about any command and you will see the general pattern. "-" is of course the subtraction operator, as in "echo $((5-3))" |
Quote:
Quote:
Let's take the tool 'tar', for example, you could do this to extract the files inside the archive 'filename.tar.gz': Code:
tar -xf filename.tar.gz Code:
tar xf filename.tar.gz As said, in linux, and conventionally, '-' or '--' are used to identify command line flags, but it is just that: a convention, a trend, just like in DOS the trend was '/' instead. These "prefixes" have no special meaning at all for the OS or the shell under normal circumstances. |
Perhaps we can agree that "it depends"......;)
The man pages are your friend.... The "-" DOES matter in many cases, even if it is not an "operator" e.g.: Code:
[mherring@Ath ~]$ cp R stuff ./stuff2 |
It can also mean standard input or standard output, in some cases.
So definitely: it depends. |
Well, I guess it's all a semantic question. This is gonna be boring, I warn you :D
As said, it's up to the tool. It has no meaning for Linux or the shell (and that was the question as I understood it). It's the tool which parses the arguments. You could easily write a program that uses '/foo' like DOS did. Some programs don't use the '-' or '--' prefixes. Some use '--' as a separator to delimit where the flags end so you can use '-' in file names, some don't. Some will use '-' to mean stdout or stdin depending on the case, overall when interacting with pipes. Some others will use some other model, like "opt=value", some others will use rc files of some type. Most of them will combine many of these schemes or even all of them. In addition '-' can be part of a file name, even the as the first character of the file name. Conclusion: '-' is not special at all. It can be user for whatever purpose, just like most other characters. You could say "well, then the blank space character is not special either because it can also be part of a file name", but then I'd answer with this: Code:
~/tmp $ touch -- -file In other words, doing "ls -l" is not different of doing "ls filename" in any sense, other than the effect it produces. ls just sees strings, there's nothing that will tell ls that "-l" is a flag and "filename" a file name, other that its internal logic. The programs parse tokens, not '-' plus 'something_else'. They read tokens from the argument list, and then parse them and act consequently. It's not <minus><l> what ls sees, bash doesn't catch the minus sign and send 'l' as a special argument (flag) to ls. It's the string '-l' as a whole which ls receives, it could be any other arbitrary string and when ls catches it, it still doesn't know if it's a file name or an option. There's nothing in the minus symbol that marks it as a flag delimiter/starter. Of course, "cp R" will not work (the intended way). Because it's the way that that tool is programmed, just like wine will accept c:\\foo, samba will accept \\foo, tar will accept xf or -xf without problems, but no other linux program will accept any of these. Each program is different, and no one should give for granted that a program will always accept -f|--foo, which seems to be the standard trend for posix and gnu respectively. What I want to emphasize is that the Linux semantics, technically speaking, don't threat '-' as a special case. Another different thing (and here, pixellany, I agree with you) is the significance that it might have *for us*, the semantic we perceive as human beings with a mental model which is shaped only by habits and nothing else, which is what I defined above as the "convention" and the "trend for posix and gnu". In that case we both agree that -f|--foo are used often to name command line flags, but that doesn't mean that what we perceive as obvious is obvious at all for the OS or the shell, because in fact, it isn't. Sorry but being that meticulous to the point of turning into an "ass", but I don't want the original poster to be confused and then shocked when he sees something like this: Code:
tar xvjpf file.tar.bz2 |
I think pwc101 is on to what the OP meant. In the case OP mentioned it means "read from standin". Like in this example:
flac -cd sound-file.flac | lame -b 320 - sound-file.mp3 the output of the first command is piped to the second command and the result is an mp3 file. |
Quote:
|
Quote:
|
Quote:
Code:
Kindly add cc to "pasha(AT)yashasvi.co.in" |
Another usage:
Code:
case:/tmp/foo/boo/moo mike$ cd /tmp |
Quote:
Quote:
|
Quote:
In this context, I think we mean to look at the man page for common commands and see how "-" is used. |
Quote:
|
To the OP: "man bash" would be the best place for you to start if you want a comprehensive guide. Also look here for a very good advanced bash guide:
http://tldp.org/LDP/abs/html You can even download it in PDF format. I love it. |
All times are GMT -5. The time now is 03:16 PM. |