How to escape "-" in bash [duplicate]

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

1 Answer

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

You Might Also Like