Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jan 2006 19:00:49 +0100
From:      Mathias Menzel-Nielsen <matze@matzsoft.de>
To:        Ronny Hippler <r11roadster@yahoo.com>
Cc:        freebsd questions <freebsd-questions@freebsd.org>
Subject:   Re: shell scripts and escaped charecters in file names
Message-ID:  <43CA8DD1.5070202@matzsoft.de>
In-Reply-To: <43C9FB5A.2050506@yahoo.com>
References:  <43C9FB5A.2050506@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Ronny Hippler wrote:

> Hello,
>     I am trying to get the following script to run with no success.
> - ------------------------------------
> #!/bin/csh
> foreach file (\*vol\*)
> mv $file `basename $file .par2`.PAR2
> echo $file
> end
> - ------------------------------------
> and get the following error:
> usage: mv [-f | -i | -n] [-v] source target
> ~       mv [-f | -i | -n] [-v] source ... directory
>
> I know it is because of the spaces and such in the file names. I have
> tried quoting single double and also escaping them but all fails. what
> is the magic? Please cc me off list. thanks!

Hi.

Sorry, dont know the trick for csh -- but for bash there is an env, 
which can be used to override word-split whitespaces:
IFS  (see bash(1))

The following script should do the trick (i have tested it with some 
filenames with spaces in it succesfully):
8<----8<----8<----
#!/bin/sh
IFS="
"
export IFS;
for i in *;
 do
         mv $i `basename $i .par2`.PAR2;
         echo $i;
done;
8<----8<----8<----8<

note how IFS is set to newline

(replace the *-wildchar in the for-line with your fileset)

Hope it helps
greetings,
    Mathias



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?43CA8DD1.5070202>