20

Possible Duplicate:
Unix tools: what if a file is named minus something?

Please tell me how to escape this:

[root@unix ~]# ./-sh
-bash: ./-sh: Permission denied
[root@unix ~]# chmod +x -sh
chmod: invalid mode: `-sh'
Try `chmod --help' for more information.
[root@unix ~]#
1
  • # chmod a+x "\\-sh" chmod: cannot access `\\-sh': No such file or directory
    – soundhax
    Jan 4, 2013 at 16:23

1 Answer 1

35

Use --.

E.g. chmod +x -- -sh. In GNU language the -- means end of options, so -sh is no longer parsed as an option.

[Edit] Added example:

beetle:/home/hennes/test>touch -- -sh

beetle:/home/hennes/test>ls -l -- -sh
-rw------- 1 hennes users 0 2013-01-04 17:20 -sh

beetle:/home/hennes/test>chmod +x -- -sh

beetle:/home/hennes/test>ls -l -- -sh
-rwx------ 1 hennes users 0 2013-01-04 17:20 -sh
1
  • 1
    Interestingly, this doesn't seem to work with GNU echo, although it works with GNU printf. This works: printf -- -sh. And this does not: echo -n -- -sh. Jun 18, 2015 at 12:50

Not the answer you're looking for? Browse other questions tagged .