On Monday 13 June 2016 05:21:23 to...@tuxteam.de wrote: > On Mon, Jun 13, 2016 at 10:19:46AM +0200, Thomas Schmitt wrote: > > Hi, > > > > Gene Heskett wrote: > > > if test ${InMail} = "gene" > > > bin/mailwatcher: line 66: test: =: unary operator expected > > > > The syntax problem is most probably about missing "-quotes around > > the variable ecaluation ${InMail} which would have to be empty to > > cause the message: > > Agreed. > > If I may add something -- one of the most difficult things for shell > novices to wrap their head around is the interaction of command line > expansion and the commands themselves. This is one of the things > which make the shell very powerful [1], but you gotta get used to it. > > Let's walk through your problem case (note that I'm restating > what Thomas said. It's just I know it's difficult and bears some > repeating :) > > You wrote: > > test ${InMail} = "gene" > > Now the shell gets a first chance at it. Suppose ${InMail} is empty. > After variable expansion, you got: > > test = "gene" > > (${InMail} was empty, so it gets replaced by nothing). Now that's > what the "if" gets fed with. It responds with "Eek! You told me > to compare *two* things and there's just one! > > One could argue "unary operator expected" is a strange way to > restate this. I didn't check, but I guess we're seeing too > deep into the bowels of if's parser. > > The solution is, as Thomas said, to put ${InMail} in double quotes. > It almost always is. The better solution is, of course: always > try to mentally follow what happens: first, expansion; then command.
Well, while the double quotes fixed it, the original actually worked. The target action of sending kmail a getmail command was carried out, Another time killer was doing a pidof -s kmail 3x in the main loop, that is handled by the while, do, done around it all. So I just took that out. And I'm still puzzled. This is a single incoming mail: + InMail=_OLB,AltXXB.coyote + test _OLB,AltXXB.coyote = gene + test _OLB,AltXXB.coyote = gene-from_linda + test _OLB,AltXXB.coyote = amanda all test failed so back at the while pidof -s kmail ++ pidof -s kmail + '[' 5179 ']' kmail is there, launch the inotifywait session. ++ /usr/bin/inotifywait -q -e close --format %f /var/spool/mail/ + InMail=gene + test gene = gene + /opt/trinity/bin/dcop kmail KMailIface checkMail + date -R + echo gene back at the top of the while ++ pidof -s kmail + '[' 5179 ']' ++ /usr/bin/inotifywait -q -e close --format %f /var/spool/mail/ So here inotifywait is seeing kmail's close as it read the file and zeroed it + InMail=gene + test gene = gene + /opt/trinity/bin/dcop kmail KMailIface checkMail + date -R + echo gene ++ pidof -s kmail + '[' 5179 ']' ++ /usr/bin/inotifywait -q -e close --format %f /var/spool/mail/ So its getting 2 checkmails because it is seeing its own activities. Put in a sleep 1 after send the getmail to kmail to see if thats enough time killer to miss that. Wasn't enough trying sleep 2 before relaunching inotifywait now. And watching paint dry, only denied spam or nothing so far. Send this, so I'll get the echo as a test msg. :) > regards > > [1] "expressive" might be the more correct term. > > -- tomás Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page <http://geneslinuxbox.net:6309/gene>