Dexter Filmore wrote:
> Since cp won't tell me about progress or txfer speed I hacked up this little
> script I called ddcp:
>
> #!/bin/bash
> #set dummy for testing
> DUM=echo
>
> #check if target is a dir or file
> #reuse source filename if it is a dir
>
> if [ -d "$2" ] ; then
> if [ ! -e "$2"/"$1" ] ; then
> $DUM dd if="$1" of="$2"/"$1"
> else
> echo target exists
> break
> fi
> else
> #if a filename is given, just use that
> $DUM dd if="$1" of="$2"
> fi
>
>
> Instead of actually running commands I first dry run them, hence the "echo".
> Now all is fine unless I got files with spaces in their names.
> Running
> $ ddcp foo\ bar morf
>
> gives me
>
> dd if=foo bar of=morf
>
> Now - how do I proper handle the space between foo and bar?
Quote handling is a perennial problem, that's for sure!
In this case, though, I think you may be worrying too much.
Just make sure every shell variable appears within double-quotes when
being evaluated (eg: commands, args, and RHS of assignments).
This rule would tell you to write
> else
> #if a filename is given, just use that
> $DUM dd if="$1" of="$2"
> fi
quoting $DUM is not important in this case, but does no harm.
I have used a remind-me-how-it-works script as follows
(from cat /usr/local/bin/argview.sh)
- - -
#!/bin/sh
echo "$# args: ($@)"
ii=0
while [ $# -gt 0 ]
do
echo "arg $((++ii))='$1'"
shift
done
#===eof===
- - -
You could use this in place of echo, for instance, as it
will tell exactly how the shell parses the command line.
Regards,
..jim
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list