如何使Bash命令将"-“识别为文件名的一部分而不是选项?
我想在Bash中转储一个名为-9的文件的内容。因此,我使用以下命令:
hexdump -C \-9在这里,我试着像逃离一个空间一样逃离-。
但是,hexdump给出了以下错误:
hexdump: invalid option -- '9'也就是说,hexdump将文件名解释为一个选项?
发布于 2017-10-17 08:44:35
我已经能够使用--标记选项的结束:
$ echo "test" > -9 # in this case it can't be understood as an option, no problem
$ hexdump -C -- -9 # -- marks the end of the options, so the -9 is understood as a filename
00000000 74 65 73 74 0a |test.|
00000005这是getopt的一个特殊性,正如其手册页中所描述的那样。
https://stackoverflow.com/questions/46785932
复制相似问题