Escape special characters in mount command

人盡茶涼 提交于 2019-12-01 04:18:41

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:

mount -t smbfs '//mydomain;user1:A%b$c%40d!e#f@server1.mydomain.com/myproject' ~/localmap

Just encode your special characters.

@ -> %40
$ -> %24
! -> %21 

Others characters can be found here: 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

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

user1=$(sed -e "s/+/%2B/g;s/@/%40/g;s/_/%5F/g" <<< "$1")

and then you can use " " and call your converted variable like this $user1

Might be handy to use nodejs to encode the url stuff:

$ 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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!