Escape special characters in mount command

22.3k views Asked by At

I am trying to mount a windows shared folder on Mac OSX Mavericks. A simplistic user name and password worked fine

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

The command tried is

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

5

There are 5 answers

3
bishop On BEST ANSWER

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#[email protected]/myproject' ~/localmap
0
midori On

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

1
the_ccalderon On

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.

1
Longfei Wu On

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
0
rigglesbee On

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