Re: OT: Need help from bash experts...
On Mon, Feb 11, 2002 at 09:22:06PM -0500, 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'm no bash expert, I'll try though.
>
> 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.
You could also do cp -r /mount/windows/spaced\ name/ target
(if you want the subdirectories included too)
>
> 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"
You don't need the \'s if you're using double quotes I believe.
Just do: 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/*
>
Okay, when you do the cp, make sure cp knows the first argument has spaces, so
do:
somedir="/mount/windows/spaced name"
cp -r "$somedir" target
or whatever, otherwise, cp gets confused and thinks the spaces seperate
different arguments
> 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
>
>
> --
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
Reply to: