Training scripts
Clint Adams
schizo at debian.org
Tue Jan 27 17:20:52 CET 2004
> #!/bin/sh
> I would love to replace for cycles with find command, but I do
> not know how to pull it off:
>
> a) to run three commands from the same find command and
> using the same {} variable twice, and
find /dir -exec firstcmd {} \; -exec secondcmd {} \; -exec thirdcmd \;
> b) does anybody know how to avoid using STR variable (i.e.,
> to use basename directly in ${...%..} bash expression)?
> ${$(basename $msg)%*:2,S} doesn't work.
This isn't a valid POSIX construct. You could do it in zsh, though you
wouldn't need to (you'd use ${${msg:r}%*:2,S} instead).
Also, if you're going to use bashisms, you should change the top line to
be #!/bin/bash, or else someone may run into trouble if you share your
script with them.
> #!/bin/sh
> find $HOME/.mail/_junk -type f -name 10\* \
> -exec formail -I "X-Bogosity:" -I "X-KMail" -ds \
> < '{}' >> $HOME/spam \;
>
> I get error ``./bogocorpus: line 5: {}: neither file nor \
> directory'' (translation to English from localized error
> messfge). Any thoughts on this?
What you are doing here is trying to redirect the contents of the file
'{}' to find, and send the output of find to $HOME/spam. Unless your
copy of find is capable of redirecting file descriptors or automatically
passes -exec clauses to a command interpreter, you'd have to do something
like fork a shell for every single formail exec.
More information about the Bogofilter
mailing list