Skip to content

Warn that POSIXLY_CORRECT=1 treats -- literally for cp, mv, & ln (at least) #3389

@Winterhuman

Description

@Winterhuman

For bugs with existing features

Here's a snippet or screenshot that shows the problem:

$ POSIXLY_CORRECT=1 ln --force --symbolic target -- file
ln: target 'file': No such file or directory
$ touch file
$ POSIXLY_CORRECT=1 ln --force --symbolic target -- file
ln: target 'file': Not a directory

What's happening is that ln can take two arguments, but POSIX ln doesn't recognise that -- isn't meant to be a filename; it's treating file as the directory to place the symbolic link under, hence the error messages.

cp & mv also suffer from this issue (e.g. POSIXLY_CORRECT=1 cp file -- file2 will fail, though strangely, POSIXLY_CORRECT=1 cp -- file file2 succeeds). There could be other tools as well, but these are the most common ones I thought to test.

Here's what shellcheck currently says:

Nothing.

Here's what I wanted or expected to see:

"Under POSIX, -- is treated as a literal filename by cp, mv, and ln."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions