Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Does anyone know how to write a shell script to install a list of applications? It's a pain to have to install each application by hand every time I set up a new system.

Edit: It still asks me Do you want to continue [Y/n]?. Is there a way to have the script input y or for it not to prompt for input?

share|improve this question
    
There used to be a program called 'yes' that did just that. (It wrote 'y' continuously to STDOUT.) –  Nathan Osman Jul 31 '10 at 0:05
add comment

4 Answers

up vote 10 down vote accepted

I would assume the script would look something like this:

#!/bin/sh
apt-get update  # To get the latest package lists
apt-get install <package name> -y
#etc.

Just save that as something like install_my_apps.sh, change the file's properties to make it executable, and run it from the command line as root.

(Edit: The -y tells apt-get not to prompt you and just get on with installing)

share|improve this answer
    
How to make it executable? I assume i would run it like: sudo ./install_my_apps.sh –  jumpnett Jul 30 '10 at 19:22
    
I'm not certain whether it's necessary to make it executable (I'm a Python guy; not much into BASH). But if you must, it can be made executable with chmod +x ./install_my_apps.sh. –  mac9416 Jul 30 '10 at 19:40
    
Or right click on it, select "Properties". In the window that opens go to the "Permissions" tab, and check the checkbox that says "Allow executing file as a program" –  jfoucher Jul 30 '10 at 20:08
4  
I don't know why this is CW, but I edited it anyway to put the -y flag. Note: If you want to make it look clearer, you can use --yes or --assume-yes in place of -y. –  Umang Aug 1 '10 at 5:20
add comment

Well, according to your question the easiest script would be:

#!/bin/sh
LIST_OF_APPS="a b c d e"

aptitude update
aptitude install -y $LIST_OF_APPS

However you could also enter aptitude update && aptitude install -y a b c d e. So maybe your question is missing the crucial point here. If there are some further requirements it would be nice to explain them.

share|improve this answer
    
Note that apt-get would work as a drop-in replacement for aptitude here, if that is your preference. Simply replace both instances of "aptitude" with "apt-get". –  mac9416 Jul 30 '10 at 18:50
add comment

Just create a list of apps in a file, example.list, and run

cat example.list | xargs sudo apt-get -y install
share|improve this answer
add comment

I would opt for the following script: vim install

#!/bin/bash
apt-get update  # To get the latest package lists
apt-get install $1 -y

Then I should make the above script executable chmod +x install. Then to use it, I could type: ./install <package_name>. Example: ./install clang

share|improve this answer
    
I wanted all the programs listed in the file. With this method, I would still have to input the name of the program as a command line argument, so there really isn't a benefit. –  jumpnett Sep 13 '12 at 19:11
    
@jumpnett Lol, I missed the list point. I am starting to lack caffeine and it shows. Sorry for it. May update the answer. –  NlightNFotis Sep 13 '12 at 19:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.