Can I add “&&” to installation instructions to speed things up?
i.e. This:
sudo add-apt-repository ppa:sandromani/gimagereader
sudo apt update
sudo apt install gimagereader
I would like one command to complete the whole process rather than having to enter 3 (or more) separate commands.
In this case I was copying and pasting the commands from a website. It would have been a lot easier to have done it once rather than three times.
Okay, sure, yes you can chain them up like that. But then you shouldn’t use sudo, as you might need to provide the corresponding password each time a && is passed.
However, another trick is, that you can just copy all commands at once and still paste them directly into the terminal.
That is, because line separators count as command separators, too. The difference between the command separators ; and && is that the former always executes all commands provided, while the latter only keeps executing commands, if each preceding and already finished command has finished execution, successfully.
If you want more knowledge regarding Bash usage, refer to guides like this one:
The manual often comes in handy too, if you need to know about advanced topics:
Thank you for that very clear explanation.
But would it not be better to use && so that if one command fails the process stops rather than ; which it seems would keep executing commands pointlessly even though the previous one failed?
And is it OK to use && but omit sudo after the first command?
Another cool and yet less known shell feature is to hold the control key and type xe
It will open your default editor, you can enter what you like and when you close it, it will execute the command.
Yes, most of the times it is useful, however in some cases it might not be necessary. Both options exist, so everyone may be happy.
It is OK, but it won’t work in your case, because all your commands require root permissions. If I were you, I would run the entire command line as the root user.
You can do that by switching to the root user, before executing the commands.
Many thanks Akito that’s cleared up a lot of things for me. And thanks to Mina also.
I’m going to give all of those suggestions a try ASAP.
Great stuff, thanks.