Greetings,

The following should work:

#!/bin/sh
sourcedir="/mount/windows/spaced name"
cp "$sourcedir"/* $target



On Monday 11 February 2002 20:22, Neal Lippman wrote:
> Sorry for OT posting; I am not sure if there is a newsgroups for bash
> experts, so I figured I'd try here.
>
> I need to be able to write a bash script that can copy files from a
> directory who's name includes a space (long story, but it's a windows
> directory under Win98 on a machine on my network).
>
> Anyway, supposing that the directory is "/mount/windows/spaced name" and I
> need to copy all of the files in the directory to a target.
>
> 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"
>
> and the cp command with various quotes and not quotes, and cannot seem to
> get this to work. Within the script, if I try:
>
> sourcedir="mount/windows/spaced\ name"
> anotherdir="mount/windows"
> echo $sourcedir/*
> echo $anotherdir/*
>
> the first echo shows that there is no expansion of the wild card, while the
> second echo works as expected, echoing the name of every file in
> /mount/windows.
>
> Clearly the problem is that dreadful space in the directory name. Any help
> on how to syntax this greatly appreciated.
>
> Thanks.
> N

Reply via email to