0

Possible Duplicate:
What does “--” (double-dash) mean?

Can anybody explain me below things

i have file named "-xyz". if i try to remove or move that file using command line , it's unable to move. i tried below things :

[rahul@srv100 ~]# ls -lrt -- "-xyz" -rw-r--r-- 1 rahul rahul 0 Dec 19 08:06 -xyz [rahul@srv100 ~]# mv "-xyz" xyz mv: invalid option -- x Try `mv --help' for more information. [rahul@srv100 ~]# mv \-xyz xyz mv: invalid option -- x Try `mv --help' for more information. [rahul@srv100 ~]# mv -\xyz xyz mv: invalid option -- x Try `mv --help' for more information. [rahul@srv100 ~]# mv '-xyz' xyz mv: invalid option -- x Try `mv --help' for more information. 

finally i rename that file using winscp, and after trying multiple ways i got one option and it's working.

mv -- '-xyz' xyz 

Wish the help of "--", i created file/directory as below

mkdir -- --abc touch -- -xyz 

So my Question is what is this "--" in bash ? Please explain.

1
  • For info, -- has nothing to do with bash. In your case, you can also use ./-xyz. Commented Dec 21, 2012 at 9:56

3 Answers 3

1

As others have already mentioned -- is used to delimit options from arguments. If you execute a program and specify any arguments the program has no way of distinguishing if the specified arguments should be interpreted as a command line option or an argument. That is the reason why a prefix for options was introduced - / -- or / on windows, i.e. -rf,--help or /?

As you may have files beginning with a such an prefix or any other special name which could be interpreted -- was introduced to delimit command line options from normal arguments, i.e. every argument after -- will not be treated as a command line option but just as a argument. getopt (1), a standard solution to parse arguments, for example supports the -- delimiter which means any program using getopt automatically supports the -- delimiter.

If you want to work with files starting with special characters like - you can also just add ./ in front of them as they now don't start with - so they won't be interpreted as command line option, for your example it would be mkdir ./--abc

1

This is used to tell the command that after that point no more command options are accepted.

So

rm -- -abc

means that it will ignore the - from the abc.

for more information you can refer to: http://tldp.org/LDP/abs/html/special-chars.html

1
  • 2
    Not really ignore the - from the -abc. Instead, it will not consider -abc to be an option, since after the --, no more options are interpreted, only arguments. Commented Dec 21, 2012 at 9:58
1

It's an indicator to the individual commands to stop interpreting further command line arguments as options.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.