Routine system update failed (Ubuntu 22.04.4 LTS)
Karl Auer
kauer at biplane.com.au
Sat Sep 21 14:28:16 UTC 2024
On Sat, 2024-09-21 at 15:56 +0200, Bo Berglund wrote:
> sudo apt update && sudo apt autoremove && sudo apt clean && sudo
> apt purge
> >
> What do all these && accomplish?
In order, they do each of the separate commands.
> AFAICT && will continue to do the next step unless an error is
> flagged, right?
Correct.
> But does it also exit the running script so following lines are not
> executed?
What running script? That is a single command line. If any of the
individual commands fails, the remaining ones will not be executed.
If the command line were part of a script, the script would continue
running, regardless of what failed. Provided there were no syntax
errors of course, and provided that none of the command explicitly
interrupted the script.
Nerd alert:
The command line is a big multiple AND statement. With AND, if anything
fails, the whole fails. So as long as each command works, the following
one will be executed. If one fails (is false), the whole expression
must be false, so there is no point executing the rest, so bash
doesn't.
If you replaced the "&&" with "||", you would instead have a big
multiple OR statement. An OR statement is true as soon as one part is
true, so the statements have to keep executing even if some fail, just
in case one of the later ones works. As soon as one works (is true),
then the whole expression is true, so there is no point executing the
rest, so bash doesn't. It's useful in a situation like
try this || try that || try something else || otherwise do this
BUT bash doesn't work entirely the way real boolean logic does. It
always operates left to right, whereas in real boolean logic the
operators have precedence. You can use parentheses to get what you want
though.
Play around with this to see how it works:
if false && false || false && true ; then
echo true
else
echo false
fi
Regards, K.
>
>
> --
> Bo Berglund
> Developer in Sweden
>
>
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au, he/him)
http://www.biplane.com.au/kauer
More information about the ubuntu-users
mailing list