simple bash script question
Matthew Gillen
me at mattgillen.net
Wed Jan 25 21:18:08 EST 2006
matthew nicholson wrote:
> and i have a another command :
>
> cat list2 | while read line; do line2=${line//\(/}; line3=${line2//\)/};
> fline=${line//\ /\\ };fline3=${fline//\(/\\\(};fline4=${fline3//\)/\\
> \)}; fline2=${line3//\ /\\ }; echo "mv $fline4 $fline2"; mv -v $fline4
> $fline2; done;
> ...
>
> however, everytime i run this, mv, with every file, says:
>
> mv: invalid option -- \
> Try `mv --help' for more information.
>
> BUT, i can copy the output of the command (it spits out the exact
> command being exectued every time mv is called) and paste it into the
> terminal, and, wham, it works. so, the syntax of what i'm passing to mv
> is, from what i can tell, correct.
The problem is you're using escaping mechanisms that are needed for the
shell's parser to determine what constitutes a single string, but when
you're invoking the command like "mv $fline4..." you've effectively done
that work for the parser, and that step gets skipped. So basically, you
need to ensure that the string you end up with as the value of $fline4
has no '\' characters in it (just like the string that the parser builds
and actually passes to the 'mv' command).
That's a gnarly enough command line that you're on your own to figure
out exactly how to go about that though...
Good luck.
--Matt
More information about the Discuss
mailing list