0

What is the difference between using - and -- in shell commands? I've seen commands like this:
pip install -U library
and:
npm i --someOption package

Is there a difference. Are they just that -- is a full word and - is only one letter?

1

1 Answer 1

2

Broadly, it's up to individual programs to decide what their parameters look like, so anything I say will not be universal.

However, by common convention, a double-dash is used for longer parameter names, and single-dash is used for single-character names. To take an example from the Linux ls command:

    -d, --directory
          list directories themselves, not their contents

So you can use either the short or long forms in this case. Further, short parameters can often be combined... e.g. you can run ls -lrt instead of ls -l -r -t, which is convenient when typing in a shell.

In contrast, the longer names are often more descriptive, so while I'd rarely use them when running commands in a shell, I'd often do so when writing scripts (where long-term readability becomes a factor).

Again though, this is only convention, and not everyone follows it. Some tools don't both with a dash at all (e.g. tar xzf filename.tar.gz), and others will use a single dash even for longer names (e.g. all of the Java command line tools).

Sign up to request clarification or add additional context in comments.

1 Comment

"(e.g. all of the Java command line tools)" - not all of them. The situation with the java command is a bit messy. Some options, such as --enable-preview, require a double dash. Other options have different behaviour depending on whether you use a single or double hash; e.g. -version vs --version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.