Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use -- for string * commands #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ilya-bobyr
Copy link

string match, string escape and friends will try to parse any argument that starts with a - as a switch. If a string being processed happens to start with a - it will, most likely, cause an "unknown option" error.

Any string cmd that uses variables, especially those containing externally provided values, should use -- to indicate the end of the string command switches and start of the positional parameters.

Consider:

    > string match '*a*b' --axxb
    string match: --axxb: unknown option

    (Type 'help string' for related documentation)

    > string match -- '*a*b' --axxb
    --axxb

This is causing real errors, for example, as git aliases may start with a switch for git itself, as in

[alias]
    dt = --paginate difftool --tool=difft

`string match`, `string escape` and friends will try to parse any
argument that starts with a `-` as a switch.  If a string being
processed happens to start with a `-` it will, most likely, cause an
"unknown option" error.

Any `string cmd` that uses variables, especially those containing
externally provided values, should use `--` to indicate the end of the
`string` command switches and start of the positional parameters.

Consider:

```fish
    > string match '*a*b' --axxb
    string match: --axxb: unknown option

    (Type 'help string' for related documentation)

    > string match -- '*a*b' --axxb
    --axxb
```

This is causing real errors, for example, as git aliases may start with
a switch for `git` itself, as in

```.gitconfig
[alias]
    dt = --paginate difftool --tool=difft
```
@ccoVeille
Copy link

Thanks. I was also struggling with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants