如何编写应用程序安装shell脚本?
有谁知道如何编写shell脚本来安装应用程序列表? 每次我建立一个新系统时,必须手动安装每个应用程序是一件痛苦的事。
编辑:它仍然问我Do you want to continue [Y/n]?
。 有没有办法让脚本输入y
或者不提示输入?
我认为脚本看起来像这样:
#!/bin/sh apt-get update # To get the latest package lists apt-get install -y #etc.
只需将其保存为install_my_apps.sh之类的内容,更改文件的属性以使其可执行,然后以root身份从命令行运行它。
( 编辑: -y
告诉apt-get
不要提示你,只是继续安装)
那么,根据你的问题,最简单的脚本将是:
#!/bin/sh LIST_OF_APPS="abcde" aptitude update aptitude install -y $LIST_OF_APPS
但是,您也可以输入aptitude update && aptitude install -yabcde
。 所以也许你的问题在这里缺少关键点。 如果有一些进一步的要求,那么解释它们会很好。
只需在文件example.list中创建应用程序列表,然后运行即可
cat example.list | xargs sudo apt-get -y install
我会选择以下脚本: vim install
#!/bin/bash apt-get update # To get the latest package lists apt-get install $1 -y
然后我应该使上面的脚本可执行chmod +x install
。 然后使用它,我可以输入: ./install
。 示例: ./install clang
#!/bin/bash set -eu -o pipefail # fail on error , debug all lines sudo -n true test $? -eq 0 || exit 1 "you should have sudo priveledge to run this script" echo installing the must-have pre-requisites while read -rp ; do sudo apt-get install -y $p ; done < <(cat << "EOF" perl zip unzip exuberant-ctags mutt libxml-atom-perl postgresql-9.6 libdbd-pgsql curl wget libwww-curl-perl EOF ) echo installing the nice-to-have pre-requisites echo you have 5 seconds to proceed ... echo or echo hit Ctrl+C to quit echo -e "\n" sleep 6 sudo apt-get install -y tig
我为此制作了一个剧本。
查看http://github.com/dinukasal/install
你也可以添加包