smbclient copy file with single quote

1.1k views Asked by At

how can i use single quote in smbclient "put" command?

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.

1

There are 1 answers

0
ghoti On

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).

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")"