开发者

How to escape an @ sign in the password field of an smb:// URL

开发者 https://www.devze.com 2023-01-13 18:39 出处:网络
I\'m trying to write a bash script in which I connect to a samba server, by getting the username and password, then saying $username:$password@SERVERNAME.

I'm trying to write a bash script in which I connect to a samba server, by getting the username and password, then saying $username:$password@SERVERNAME.

However, this will fail if the password has an @ in it. Is there a way to escape the @ out of the password in bash?

Thanks in advance

Update: I'm setting up this network printer

lpadmin -p PRINTER -v smb://$username:$password@SERVER -E

and it works except in the case tha开发者_开发问答t $password has an @ sign in it; the $username and $passwords variables are gotten from reading stdin


Ah, no, this isn't actually a matter of quoting for Bash, but quoting for Samba. You have this:

lpadmin -p PRINTER -v smb://$username:$password@SERVER -E

which Bash dutifully expands to

lpadmin -p PRINTER -v smb://alice:passw@rd@SERVER -E

and then the Samba client library thinks the password ends at the first @ sign and it's supposed to connect to a server named rd@server, never mind that you can't actually put that name in the DNS.

lpadmin comes from CUPS, not from Samba (here is its manpage) and, reading through those docs a bit, I think you may be able to use this alternate syntax:

lpadmin -p PRINTER -U "${username}%${password}" -v smb://SERVER -E

I'm surprised escaping @ as %40 doesn't work, though. Looks like a bug in the samba client library to me.


I use the cups admin at http://localhost:631/ to add printers. Encoding @ as %40 worked for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号