On Tue, Apr 21, 2009 at 11:51:01AM +0200, Per Jessen wrote:
Dominique Leuenberger wrote:
On 4/21/2009 at 11:37, Per Jessen <per@opensuse.org> wrote: Dominique Leuenberger wrote:
Hi,
I'm busy writing a script that does 'something' with every file found.
It does something like:
for a in $( find /mnt/Data/Todo -type f -exec basename {} \; ); do /usr/bin/stcommand $a /usr/bin/2ndcommand $a done
The problem here is simply: it works only as long as the filename does not contain any whitechars :(
Is there a good way to get around this?
Put $a in double qoutes.
Per, that solution was to easy and of course is not true (the original script actually has them quoted)
The problem happens in line for a already where 'for' is splitting the array of chars at the white chars.
I guess it I didn't take enough time to read through everything, sorry. How about this slightly changed script: (not tested)
find /mnt/Data/Todo -type f -exec basename {} \; | while read a do /usr/bin/stcommand $a /usr/bin/2ndcommand $a done
shopt -s globstar OIFS="$IFS" IFS=$'\n' for a in /mnt/Data/Todo/** ; do test -f "$a" || continue a="${a##*/}" /usr/bin/stcommand "$a" /usr/bin/2ndcommand "$a" done IFS="$OIFS" ... OK the `**' trick for listing subdirectories works only for bash 4.0 ... for a plain directory simply use `*' ... on the other hand the GNU find also shows an option -printf: find /mnt/Data/Todo/ -type f -printf '%f\n' to avoid the `-exec {} \;' Werner -- "Having a smoking section in a restaurant is like having a peeing section in a swimming pool." -- Edward Burr -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org