Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 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:[email protected]/folder/ mountpoint

But my password contains backticks!

How would I quote this?

I've tried:

mount_smbfs //username:`123`[email protected]/folder/ mountpoint

And single quotes:

mount_smbfs '//username:`123`[email protected]/folder/' mountpoint

And a variable:

pw='`123`123'
mount_smbfs //username:[email protected]/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 Answer

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`[email protected]/folder/

or

mount_smbfs '//username:my`[email protected]/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`[email protected]/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%[email protected]/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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...