On Monday 11 February 2002 21:22, Neal Lippman wrote: [...] > At a bash prompt, I can issue either: > cp "/mount/windows/spaced name/*" target > OR > cp /mount/windows/spaced\ name/* target > and all works fine. > > However, from within a bash script, something like: > > #!/bin/sh > sourcedir=/mount/windows/spaced\ name > cp $sourcedir/* target > > fails, because the space isn't properly passed to cp, AND > further the shell doesn't do expansion on the wild card in the > file name. > > I have tried all sorts of variants: > sourcedir="/mount/windows/spaced\ name" > sourcedir="/mount/windows/spaced\\ name" > sourcedir=/mount/windows/spaced\\ name"
#!/bin/bash # title: do_it sourcedir='spaced name' destdir=done cp -R "${sourcedir}" ${destdir} It should also handle any other nasty names below that. Of course, you'll need to test it more than this. Here's a simple test: [EMAIL PROTECTED]:~/bin/testing$ ls do_it spaced name [EMAIL PROTECTED]:~/bin/testing$ ls spaced\ name/ num 3 num1 num2 [EMAIL PROTECTED]:~/bin/testing$ ./do_it [EMAIL PROTECTED]:~/bin/testing$ ls do_it done spaced name [EMAIL PROTECTED]:~/bin/testing$ ls done num 3 num1 num2 [EMAIL PROTECTED]:~/bin/testing$ hth, Jesse