我有一个名为的目录:
-2
我想要进入它,但CD抱怨:
bash: cd: -2: invalid option
没有成功,我试过:
cd "-2"
cd '-2'
cd -2
有解决方案吗
编辑:服务器上没有像mc等文件浏览器.
解决方法
至少有两种方式:
>使用 – 参数.
cd -- -2
这使用GNU工具常用的约定,它不会处理之后出现的任何内容 – 作为命令行选项.
正如commenter所述,该公约也是defined in the POSIX standard:
Default Behavior: When this section is listed as “None.”,it means that the implementation need not support any options. Standard utilities that do not accept options,but that do accept operands,shall recognize "--" as a first argument to be discarded.
The requirement for recognizing "--" is because conforming applications need a way to shield their operands from any arbitrary options that the implementation may provide as an extension. For example,if the standard utility foo is listed as taking no options,and the application needed to give it a pathname with a leading hyphen,it could safely do it as:
06001
and avoid any problems with -m used as an extension.
as well as:
Guideline 10: The argument -- should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands,even if they begin with the '-' character. The -- argument should not be used as an option or as an operand.
>明确指定路径:
cd ./-2
这指定了显式命名当前目录(.)作为起点的路径.
cd $(pwd)/-2
cd /absolute/path/to/-2
这些是上面的变化.任何数量的此类变化都是可能的;我将把它作为练习留给读者发现所有这些.
(编辑:常州站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|