Speed up app installation in terminal

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

To This:
sudo add-apt-repository ppa:sandromani/gimagereader && sudo apt update && sudo apt install gimagereader

Greetings, @John_Pie.

Please describe your issue as detailed as possible.

What do you mean when you say “speed things up”?

Do you want to “speed up” your typing on the keyboard or do you want to “speed up” whatever the bash commands do or what do you want to “speed up”?

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.

Copy all the following command lines:

sudo add-apt-repository ppa:sandromani/gimagereader
sudo apt update
sudo apt install gimagereader

And just paste them into your shell and press ENTER. Yes, this works.

Copy-pasting commands like this are technically equivalent to doing this:

sudo add-apt-repository ppa:sandromani/gimagereader ; sudo apt update ; sudo apt install gimagereader

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:

1 Like

I use the semicolon variant really often.

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.

2 Likes

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.

Alternatively, you can do something like this:

sudo bash -c 'add-apt-repository ppa:sandromani/gimagereader && apt update && apt install gimagereader'

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.

1 Like