Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 1299  / 1 Year ago, tue, may 2, 2023, 8:58:47

I've noticed that the majority of Ubuntu help websites present apt commands in the following format:



sudo add-apt-repository ppa:[ppa-address]
sudo apt-get update
sudo apt-get install [application-name]


But I know that apt commands like this one work too:



sudo add-apt-repository ppa:[ppa-address] && sudo apt-get update && sudo apt-get install [application-name]


Is there a particular reason that most sites present in the first format? Are there known issues with chaining commands with &&, or to put it another way are there any benefits/drawbacks to using either method?



Further, other then loss of internet, are there any circumstances in which an apt command might fail?


More From » apt

 Answers
0

Personally, I think sites list them one by one just for clarity. It's easier to run one at a time and understand what it does then it is to run, say 3, all at once.



I might point out too, not all sites do list commands one by one. For example, in the OMG Ubuntu article on installing Unity Tweak Tool the commands are listed as:



sudo add-apt-repository ppa:freyja-dev/unity-tweak-tool-daily  
sudo apt-get update && sudo apt-get install unity-tweak-tool


It's also worth noting that && will only run the second or third (etc) command if the command before it returns exit status 0. In other words, the command after && will only be run if the command before && completes successfully.



If you'd like your string of commands to execute one by one no matter if any fail you would separate each command with ; instead of &&. For example:



sudo add-apt-repository ppa:[ppa-address] ; sudo apt-get update ; sudo apt-get install [application-name]  


(Of course, this wouldn't be a good thing to do when installing packages!)



There are a number of reasons why an apt command would fail:




  • apt-get install could fail for quite a few reasons, among them dependency issues, not enough disk space, no internet connection, or an old or malformed sources.list file.


  • apt-get update could fail for similar reasons, a malformed sources.list, no internet connection, a 404 PPA, etc.




These are just some of the things that would cause apt to fail, causing commands after && to not be run.


[#31289] Tuesday, May 2, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neasinient

Total Points: 491
Total Questions: 120
Total Answers: 93

Location: The Bahamas
Member since Mon, Aug 2, 2021
3 Years ago
neasinient questions
;