I'm trying to use smbclient in a bash script to make a directory on a remote windows server.

Whilst this works:

smbclient -U "DOMAIN/$username" "//remoteserver/folder with spaces" --directory "Another folder with spaces/" -c "mkdir /newfolder/"

This doesn't:

smbclient -U "DOMAIN/$username" "//remoteserver/folder with spaces" --directory "Another folder with spaces/" -c "mkdir /folder to create with spaces/"

Instead a folder simply called 'folder' is created. I've tried many variations like the following:

"mkdir /folder\ to\ create\ with\ spaces/"
"mkdir '/folder to create with spaces/'"
'mkdir '/folder to create with spaces/''

but can't seem to find the magic combination.

  • The escape char isn't /, it is \. So give mkdir '/folder\ to\ create\ with\ spaces' a try. – Panki Apr 9 at 11:46
  • Apologies - mistake in my question write up - I did try \ not / - question updated. – Chris Nevill Apr 9 at 11:56
  • What is the difference supposed to be between the 2nd and the 4th? (-: – JdeBP Apr 9 at 12:53
  • Ooops! :) edited – Chris Nevill Apr 9 at 13:28

These options should work:

  • -c 'mkdir "folder to create with spaces"'
  • -c "mkdir \"folder to create with spaces\""
  • That's worked great thanks :) – Chris Nevill Apr 9 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.