crontab bash tests

Ralf Mardorf kde.lists at yahoo.com
Tue Sep 26 13:28:16 UTC 2023


My apologies I made a few copy & paste errors. Actually the difference
between bash and dash does explain what's going on. IIUC this was
already mentioned by the thread before I chimed in.

   • rocketmouse at archlinux ~ 
   $ dash -i
   $ { [ $(true)$? -eq 0 ] && true || echo "Hello Kitty"; }
   $ { [[ $(true)$? -eq 0 ]] && true || echo "Hello Kitty"; }
   dash: 2: [[: not found
   Hello Kitty
   $ exit
    rocketmouse at archlinux ~ 
   $ bash -i
   • rocketmouse at archlinux ~ 
   $ { [[ $(true)$? -eq 0 ]] && true || echo "Hello Kitty"; }
   • rocketmouse at archlinux ~ 
   $
   
So this does explain why rm does run when using cron, but does not run
by command line.

The OP claimed:
"Whether
if ..
[ ..
[[ ..
and I tried them all, outside of _cron_ the same command line,
copy&paste, works as expected, tests works as expected."

Maybe the OP has done the same as I've done, mistakes when doing the
copy & paste. Apart from this we need to keep in mind that the one-liner
script fails if the "touch" command for any reason should return an exit
status not equal to 0, in this case "rm" is run, too.



More information about the ubuntu-users mailing list