LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2009, 10:03 AM   #1
khalidpashamce
LQ Newbie
 
Registered: May 2009
Posts: 1

Rep: Reputation: 0
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"
 
Old 09-25-2009, 10:31 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Welcome to LQ!!

Quote:
Kindly add cc to "pasha@yashasvi.co.in"
NO!!--Please do not expect people to send you e-mail answers. Questions and answers should be kept on the forum so everyone can benefit.

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))"
 
Old 09-25-2009, 10:44 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by pixellany View Post
Welcome to LQ!!

NO!!--Please do not expect people to send you e-mail answers. Questions and answers should be kept on the forum so everyone can benefit.

I STRONGLY RECOMMEND that you remove your e-mail address above---you are inviting a SPAM attack.
I concur, putting your email address in a public forum is inviting spammers to your account.

Quote:
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.
Not even that. There's nothing special about '-'. Each command parses the options on its own way. The fact that *most* tools will recognize tokens starting with '-' as command line flags/options is only a convention, and not anything that's enforced by Linux, or that has a special meaning to the shells or Linux itself in general.

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
But tar will also work if you do:

Code:
tar xf filename.tar.gz
To sum up, it's just up to the tool at hand to parse the arguments and decide what do they mean.

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.
 
Old 09-25-2009, 12:17 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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
cp: target `./stuff2' is not a directory
[mherring@Ath ~]$ cp -R stuff ./stuff2
[mherring@Ath ~]$   (copied successfully)
 
Old 09-25-2009, 12:26 PM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
It can also mean standard input or standard output, in some cases.

So definitely: it depends.
 
Old 09-25-2009, 01:09 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Well, I guess it's all a semantic question. This is gonna be boring, I warn you

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
~/tmp $ ls -l -- -file
-rw-r--r--    1 i92guboj i92guboj        0 Sep 25 18:29 -file
Unlike blank spaces, '-' doesn't need escaping or quoting, because it's not special in any regard. It's just a normal character. And "what will it mean" will only depend on the application that receives the argument, not in Linux, nor even in your shell.

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
mplayer vo=x11 foo.avi
wget -q -O -
ls -l -- -my-file-name.doc
We should give nothing for granted and check always the man pages or whatever docs are available

Last edited by i92guboj; 09-25-2009 at 01:17 PM. Reason: added ls example with weird file name
 
Old 09-25-2009, 01:09 PM   #7
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 90
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.
 
Old 09-25-2009, 01:46 PM   #8
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,613

Rep: Reputation: 433Reputation: 433Reputation: 433Reputation: 433Reputation: 433
Quote:
Can you let me what is function of this operator " - " in linux.
"separator flag"
 
Old 09-25-2009, 03:03 PM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by malekmustaq View Post
"separator flag"
No!!! If you read this thread, you will see that almost none of the usages are anything like a "separator flag".

Last edited by pixellany; 09-25-2009 at 06:28 PM. Reason: typo
 
Old 09-26-2009, 02:23 AM   #10
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by khalidpashamce View Post
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(AT)yashasvi.co.in"
That depends. What does "I love you" mean? The symbol "-" has just as many meanings. No, wait, it has more.

Code:
Kindly add cc to "pasha(AT)yashasvi.co.in"
Never ask for an e-mail response. This is a public forum, not a private consulting service. Also, get ready to replace your e-mail address.
 
Old 09-26-2009, 05:02 AM   #11
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
Another usage:

Code:
case:/tmp/foo/boo/moo mike$ cd /tmp
case:/tmp mike$ cd -
/tmp/foo/boo/moo
case:/tmp/foo/boo/moo mike$
 
Old 09-26-2009, 10:42 AM   #12
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Rep: Reputation: 34
Quote:
Originally Posted by khalidpashamce View Post
Pls explain me its role, Kindly add cc to "pasha@yashasvi.co.in"
There's an option to subscribe to this thread so you can receive email notifications.

Quote:
We should give nothing for granted and check always the man pages or whatever docs are available
Call me a fool for attempting man - but what do I look for?

Last edited by gregorian; 09-26-2009 at 10:46 AM.
 
Old 09-26-2009, 10:53 AM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by gregorian View Post
There's an option to subscribe to this thread so you can receive email notifications.


Call me a fool for attempting man - but what do I look for?
"-" is not a command, so I would not expect to find a man page for it...

In this context, I think we mean to look at the man page for common commands and see how "-" is used.
 
Old 09-27-2009, 01:38 AM   #14
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by gregorian View Post
There's an option to subscribe to this thread so you can receive email notifications.


Call me a fool for attempting man - but what do I look for?
Mmmmmm, if you want to take it personal it's your problem, but... during all that post, I quoted "pixellany", not you, sorry, and you are taking this out of context, completely, I only wanted to help. Sorry. I quit.

Last edited by i92guboj; 09-27-2009 at 01:39 AM. Reason: s/quote/quoted/g
 
Old 09-27-2009, 09:36 AM   #15
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 90
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"substraction" and "division" function in OpenOffice Calc mac1234mac Linux - Software 7 12-03-2009 07:36 AM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 11:47 AM
When "function pointer" meets "template"... I can't get rid of this compiling er cyu021 Linux - Software 3 12-17-2004 08:52 PM
"Function not implemented" error in call to "sem_open()" Krishnendu8 Linux - Newbie 1 06-07-2003 03:52 AM
"Function not imlemented" error in call to "sem_open()" Krishnendu8 Linux - Networking 0 06-07-2003 03:19 AM


All times are GMT -5. The time now is 10:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration