如何在 zsh 中用反引号引用字符串?
How to quote string with backtick in zsh?
我需要使用像
这样的行来挂载 SMB 共享
mount_smbfs //username:password@server.com/folder/ mountpoint
但是我的 password
包含反引号!
我怎么引用这个?
我试过:
mount_smbfs //username:\`123\`123@server.com/folder/ mountpoint
和单引号:
mount_smbfs '//username:`123`123@server.com/folder/' mountpoint
还有一个变量:
pw='`123`123'
mount_smbfs //username:$pw@server.com/folder/ mountpoint
这些都给我
mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument
与处理任何包含需要转义字符的字符串的方式相同:
mount_smbfs //username:my\`password@server.com/folder/
或
mount_smbfs '//username:my`password@server.com/folder/'
不能单独使用双引号,因为双引号字符串中的反引号被解释为命令替换的开始。你可以写
mount_smbfs "//username:my\`password@server.com/folder/"
根据错误消息,问题不是保护反引号免受 shell 的影响,而是来自 URL 解析库的问题。尝试
mount_smbfs '//username:%60123%60123@server.com/folder/' mountpoint
其中 %60
是反引号的 URL 引号形式。无论如何引用 URL 是一个好习惯:不要将任何你不想处理的内容暴露给 shell,即使你确定 shell 没有任何内容会处理。
我需要使用像
这样的行来挂载 SMB 共享mount_smbfs //username:password@server.com/folder/ mountpoint
但是我的 password
包含反引号!
我怎么引用这个?
我试过:
mount_smbfs //username:\`123\`123@server.com/folder/ mountpoint
和单引号:
mount_smbfs '//username:`123`123@server.com/folder/' mountpoint
还有一个变量:
pw='`123`123'
mount_smbfs //username:$pw@server.com/folder/ mountpoint
这些都给我
mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument
与处理任何包含需要转义字符的字符串的方式相同:
mount_smbfs //username:my\`password@server.com/folder/
或
mount_smbfs '//username:my`password@server.com/folder/'
不能单独使用双引号,因为双引号字符串中的反引号被解释为命令替换的开始。你可以写
mount_smbfs "//username:my\`password@server.com/folder/"
根据错误消息,问题不是保护反引号免受 shell 的影响,而是来自 URL 解析库的问题。尝试
mount_smbfs '//username:%60123%60123@server.com/folder/' mountpoint
其中 %60
是反引号的 URL 引号形式。无论如何引用 URL 是一个好习惯:不要将任何你不想处理的内容暴露给 shell,即使你确定 shell 没有任何内容会处理。