For instance I have many aliases for Terminal created so that with one command I can execute many commands, so I may have a command to update rkhunter which also does freshclam, which is basically this:

sudo rkhunter --update && sudo rkhunter --versioncheck && sudo freshclam

And I may even want to automate this task so that it runs every hour or so, however with this there is a problem, for if anyone of those commands fails, then the command after it (if there is one), will not be executed. And as this may also be an automated task, I won't even know that somewhere down the line something is failing which is meaning that everything beyond that point is not even going to be run.

And as this is a major problem for me at the moment especially if I want to automate tasks through aliases and the such without creating a script etc, is there any way of making it so that if one of the commands fail for the next command after the && to still be run?

Also, another thing is that this does not happen all of the time, in fact sometimes it fails and still runs the next command, but at most times it does not, so there is really even any way of predicting whether it is going to fail or not, and I'm not even too sure why it is failing.

So is there a way to fix this, and why is it failing anyway?



sudo rkhunter --update; sudo rkhunter --versioncheck; sudo freshclam

or, if you need logical operations

sudo rkhunter --update || sudo freshclam
sudo rkhunter --update && sudo rkhunter --versioncheck; sudo freshclam

Make some simple tests with echo

  • echo -n a; echo -n b; echo -n c

  • echo -n a && echo -n b; echo -n c

  • echo -n a || echo -n b; echo -n c



The ; between the commands is no more than a separator between two or more commands, without considering an error.

It's the same as a list of commands in a script


OTOH, && (logical conjunction) and || (logical disjunction) are logical operations.

  • &&   If one condition fails, it makes no sense to check the second or third condition. The result would be the same: failure already.

     A  B   A ∧ B
     T  T   T
     T  F   F
     F  T   F
     F  F   F
  • ||   If, and only if, one condition fails, it makes sense to check the second and the third condition. If the first command succeeds, the second one won't be executed, because the result is deemed to be success already.

     A  B   A ∨ B
     T  T   T
     T  F   T
     F  T   T
     F  F   F
  • Could you please also explain what the difference is between using ; and &&, and why is makes this large difference?
    – user364819
    Jul 19 '15 at 16:52
  • @ParanoidPanda Sure ;) done.
    – A.B.
    Jul 19 '15 at 17:03
  • @leftaroundabout the part || sounds logically, but it's really true? I think I have tested and the third command was executed after the fail of the first command and the success of the second.
    – A.B.
    Jul 19 '15 at 19:53
  • @A.B.: try echo 'bla' || echo 'blu'. It only prints bla. Jul 19 '15 at 19:54
  • @leftaroundabout yes, certainly you're right. I was a little bit confused
    – A.B.
    Jul 19 '15 at 20:02

I'm going to throw in my two cents worth here.

If you run from a terminal window the following commands, they allow you to configure both the rkhunter and freshclam for when their updates will be run. Freshclam actually has a daemon that can run as many times a day as you want. During the configuration process of freshclam it asks how many times a day to check for updates. It defaults to 24 which means once per hour. rkhunter on the other hand runs a daily scan, but updates weekly.

freshclam configure:

sudo dpkg-reconfigure clamav-freshclam

rkhunter configure:

sudo dpkg-reconfigure rkhunter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy