bash 转义挂载命令中的特殊字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27026168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Escape special characters in mount command
提问by Karthick
I am trying to mount a windows shared folder on Mac OSX Mavericks. A simplistic user name and password worked fine
我正在尝试在 Mac OSX Mavericks 上安装 Windows 共享文件夹。一个简单的用户名和密码工作正常
mount -t smbfs //user2:[email protected]/myproject ~/localmap
mount -t smbfs //user2:[email protected]/myproject ~/localmap
On trying out the more valid user name and password I am getting errors that parsing URL failed. The details are Username: mydomain\user1 Password: A%b$c@d!e#f
在尝试更有效的用户名和密码时,我收到解析 URL 失败的错误。详细信息是用户名:mydomain\user1 密码:A%b$c@d!e#f
The command tried is
尝试的命令是
mount -t smbfs //mydomain\user1:A%b\$c\@d\!e#[email protected]/myproject ~/localmap
mount -t smbfs //mydomain\user1:A%b\$c\@d\!e#[email protected]/myproject ~/localmap
Based on what I found, $ and ! needs to be escaped. Need help on how to escape the special characters. Incidentally, using only the username without the domain seems to work in the first case
根据我的发现, $ 和 ! 需要逃脱。需要有关如何转义特殊字符的帮助。顺便说一句,只使用没有域的用户名似乎在第一种情况下有效
采纳答案by bishop
Single quotes escape shell meta-characters, a semi-colon should separate the domain controller from the credentials, and can use %40
to represent an @
in the password:
单引号转义 shell 元字符,分号应将域控制器与凭据分开,并可用于%40
表示@
密码中的an :
mount -t smbfs '//mydomain;user1:A%b$c%40d!e#[email protected]/myproject' ~/localmap
回答by Longfei Wu
Just encode your special characters.
只需对您的特殊字符进行编码。
@ -> %40
$ -> %24
! -> %21
Others characters can be found here: http://www.degraeve.com/reference/urlencoding.php
其他字符可以在这里找到:http: //www.degraeve.com/reference/urlencoding.php
e.g.
例如
username="someone", password="passw@rd"
Then this should work for you:
那么这应该适合你:
mount -t smbfs //someone:passw%40rd@server/path /Volumes/path
回答by rigglesbee
Might be handy to use nodejs to encode the url stuff:
使用 nodejs 对 url 内容进行编码可能会很方便:
$ node -e 'console.log(encodeURIComponent("A%b$c@d!e#f"))'
A%25b%24c%40d!e%23f
Decode to go the other way:
解码以另一种方式:
$ node -e 'console.log(decodeURIComponent("A%25b%24c%40d!e%23f"))'
A%b$c@d!e#f
回答by midori
Use \
to escape special symbols
if you want to convert some special symbols you can write additional string, where $1 - is parameter you provide for converting
使用\
转义特殊符号,如果你想要一些特殊符号转换,你可以写更多的字符串,其中$第1 -是参数你提供转换
user1=$(sed -e "s/+/%2B/g;s/@/%40/g;s/_/%5F/g" <<< "")
and then you can use " "
and call your converted variable like this $user1
然后你可以" "
像这样使用和调用你转换后的变量$user1
回答by the_ccalderon
Please see https://serverfault.com/questions/309429/mount-cifs-credentials-file-has-special-character, the first answer there worked for me. Basically, you create a file with the credentials and then specify that file instead of your username and password.
请参阅https://serverfault.com/questions/309429/mount-cifs-credentials-file-has-special-character,那里的第一个答案对我有用。基本上,您使用凭据创建一个文件,然后指定该文件而不是您的用户名和密码。