日期:2014-05-16  浏览次数:20763 次

Linux下一键安装软件脚本
功能:一键安装软件。可以选择要安装的选项(如1 2 3 ),直接回车的话,默认全安装

#!/bin/sh:/bin/bash  
export PATH=/usr/bin:/bin:/sbin:/usr/sbin:$PATH

init_env()
{
    echo "初始化环境"
    #yum install ncurses*  gcc+ gcc-c++ openssl* gcc gcc++  cmake
}

install_vim()
{
    echo "安装Vim"
}

do_install()
{
    for a in "$@"
    do
        echo "执行:"${arry[$a]}
        ${arry[$a]}
    done
}


arry[1]="init_env";
arry[2]="install_vim"
#${arry[1]}
#${arry[2]}

echo "please choose which you want to setup."
echo -e "1:init_env \t 2:install_vim"
read -a choosed
if [ -z "$choosed" ]
then
    echo "no choose"
    do_install ${arry[@]}
else
    echo "choose"
    do_install  ${choosed[@]}
fi


运行举例:
#sh b.sh 
please choose what you want to setup.
1:init_env       2:install_vim
1
choose
执行:init_env
初始化环境