简体   繁体   English

smbclient复制文件带有单引号

[英]smbclient copy file with single quote

how can i use single quote in smbclient "put" command? 如何在smbclient“ put”命令中使用单引号?

For example: 例如:

smbclient -c 'put "/mydir/video.avi" "\Music\Guns N' Roses\video.avi"'

The ' in "Guns N' Roses" generate an error, but i cannot use "Guns N\\' Roses", because will change path. “ Guns N'Roses”中的'会产生错误,但我不能使用“ Guns N \\'Roses”,因为这会改变路径。

Your shell doesn't allow use of escaped single quotes inside a single-quoted string. 您的外壳程序不允许在单引号引起来的字符串中使用转义的单引号。 Read the section entitled "QUOTING" in man bash (assuming your shell is bash). 阅读man bash “ QUOTING”一节(假设您的shell是bash)。

You need to escape the inner single quotes outside the single-quoted string: 您需要在单引号字符串之外转义内部单引号:

smbclient -c 'put "/mydir/video.avi" "\Music\Guns N'\'' Roses\video.avi"'

Or, if you prefer: 或者,如果您愿意:

smbclient -c 'put "/mydir/video.avi" "\Music\Guns N'"'"' Roses\video.avi"'

Or alternately, you could put things in variables, use formatting, etc. Obviously I haven't tested this in your environment, but the following seems reasonable to me: 或者,您也可以将其放入变量中,使用格式等。显然,我尚未在您的环境中对此进行测试,但是以下内容对我来说似乎很合理:

$ source="/mydir/video.avi"
$ target="\Music\Guns N' Roses\video.avi"
$ cmd='put "$s" "$s"'
$ smbclient -c "$(printf "$cmd" "$source" "$target")"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM