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 ~]#
soundhax
  • 603
  • 2
  • 5
  • 10

1 Answers1

33

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
Hennes
  • 64,768
  • 7
  • 111
  • 168
  • 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`. – Lukas Pokorny Jun 18 '15 at 12:50