Re: OT: Need help from bash experts...
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:
jesse@leisure:~/bin/testing$ ls
do_it spaced name
jesse@leisure:~/bin/testing$ ls spaced\ name/
num 3 num1 num2
jesse@leisure:~/bin/testing$ ./do_it
jesse@leisure:~/bin/testing$ ls
do_it done spaced name
jesse@leisure:~/bin/testing$ ls done
num 3 num1 num2
jesse@leisure:~/bin/testing$
hth,
Jesse
Reply to: