Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

quoting - How to quote string with backtick in zsh?

I need to mount an SMB share with a line like

mount_smbfs //username:password@server.com/folder/ mountpoint

But my password contains backticks!

How would I quote this?

I've tried:

mount_smbfs //username:`123`123@server.com/folder/ mountpoint

And single quotes:

mount_smbfs '//username:`123`123@server.com/folder/' mountpoint

And a variable:

pw='`123`123'
mount_smbfs //username:$pw@server.com/folder/ mountpoint

All of which give me

mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument

question from:https://stackoverflow.com/questions/66050910/how-to-quote-string-with-backtick-in-zsh

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The same way you do any string that contains characters that need to be escaped:

mount_smbfs //username:my`password@server.com/folder/

or

mount_smbfs '//username:my`password@server.com/folder/'

You can't use double quotes alone, because the backtick in a double-quoted string is interpreted as the start of a command substitution. You could write

mount_smbfs "//username:my`password@server.com/folder/"

Based on the error message, the problem isn't protecting the backtick from the shell, but from the URL parsing library. Try

mount_smbfs '//username:%60123%60123@server.com/folder/' mountpoint

where %60 is the URL-quoted form for a backtick. Quoting the URL anyway is good practice: don't expose anything you don't want processed to the shell, even if you are sure there's nothing that the shell would process.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...