cygwin:pdksh(5.2.14-3) 不支持反斜杠路径 (\)
作为 cygwin 下 ksh 的替代品,pdksh 可能是唯一的选择。但看起来 cygwin 有一个错误:pdksh(5.2.14-3) 支持反斜杠路径 (\)。
它会吞掉\:
$ cd .\access
pdksh: cd: /cygdrive/e/.access - No such file or directory
在网上搜索后,其他平台也解决了同样的问题。但不知道如何解决 cygwin 的问题。
as an replacement for ksh under cygwin, pdksh might be the only choice. but look like there have a bug for cygwin : pdksh(5.2.14-3) to support backslash path (\).
it will swallow the \ :
$ cd .\access
pdksh: cd: /cygdrive/e/.access - No such file or directory
After search on the internet, the same problem solved for other platform. but no idea how to solve it for cygwin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Pdksh 与所有 Cygwin 程序一样,支持反斜杠作为目录分隔符。但你必须正确引用它们。在 Cygwin 下运行 shell 脚本确实可以教会您正确引用内容,特别是始终将变量替换放在双引号中,并且不要粗心地使用 echo (
printf "%s" "$x"< /code> 是可移植且可靠的:与
echo
不同,它不存在可能进行反斜杠扩展的风险)。请注意,pdksh 与 ksh88 的兼容性也远非完美,因此某些脚本可能会因其他原因而失败(例如依赖
writer | reader
的状态代码为reader
,这是 true ksh 中的情况,但不是 pdksh 中的情况)。 Cygwin 包含zsh
,在运行emulate ksh
后,它基本上与 ksh88 兼容(尽管仍然不完美)。适用于 Windows 的 ksh 有非 Cygwin 端口,包括
SUA 和 ATT 自己的端口。InterixSFUPdksh, like all Cygwin programs, does support backslashes as directory separators. But you have to quote them properly. Running shell scripts under Cygwin really teaches you to quote things properly, in particular to always put variable substitutions in double quotes, and not use echo carelessly (
printf "%s" "$x"
is portable and reliable: unlikeecho
, there's no risk that it might do backslash expansion).Note that pdksh's compatibility with even ksh88 is far from perfect, so some scripts may fail for other reasons (such as relying on the status code of
writer | reader
being that ofreader
, which is the case in true ksh but not in pdksh). Cygwin includeszsh
, which after you runemulate ksh
is mostly compatible with ksh88 (though still not perfect).There are non-Cygwin ports of ksh for Windows, including
SUA and ATT's own port.InterixSFU您必须使用正斜杠,或将所有反斜杠加倍,或将可能是路径名的每个字符串用单引号引起来。抱歉,没有办法解决这个问题。这是尝试在 Windows 上使用 Unix shell 时遇到的常见问题,其中 \ 是转义字符。
You have to use forward slashes, or double all the backslashes, or single-quote every string that might be a pathname. Sorry, there's no way around this. This is a general problem with trying to use Unix shells, for which \ is an escape character, on Windows.
来自 Cygwin 用户指南:
有一个名为
cygpath
< 的实用程序/a> 设计用于在 Win32 和 POSIX 路径之间转换每种方式的 shell 脚本中使用。From the Cygwin User's Guide:
There is a utility called
cygpath
that is designed to be used in shell scripts that converts each way between Win32 and POSIX paths.这是该问题的解决方法。开始使用 bash 并在配置文件中进行以下修改。
在最后添加以下代码
<前><代码>wcd()
{
cd $(echo "$@" | sed 's/\\/\\\\/g')
}
保存
类型
加上引号,瞧,您就有了自己的 Windows 兼容的 cd 命令。
Here's a workaround for the problem. Start using bash and make the following modifications in config files.
Add the following code at the end
Save it
Type
along with the quotes and voila, you have your own windows compatible cd command.