1)什么是shell脚本
文档:<u>http://www.runoob.com/linux/linux-shell.html</u>
概念:shell脚本与window下的批处理相似,它是一个用C语言编写的程序
shell命令指linux命令,如:ls、pwd、init等
shell脚本指一堆linux命令的集合
2)初体验(创建第一个shell脚本,输出hello dog)
步骤1:创建.sh结尾的文件
步骤2:通过vi命令打开该文件,并在文件头输入固定格式【#!/bin/bash】
步骤3:另一个一样输入任意liunx命令即可
步骤4:保存并退出,然后通过命令运行【sh 文件名.sh】
创建.png
3)判断
#创建变量
Select_Id=3
#判断
if [ $Select_Id == 1 ]; then
echo d111
elif [ $Select_Id == 2 ]; then
echo 2222
elif [ $Select_Id == 3 ]; then
echo 3333
else
echo 'no select id, exit...'
exit 1
fi
4)菜单选择
菜单选择.pngecho "
Please Select Install
# ---------------------------------------
1 --- Linux + Apache + MySql + PHP5.3 ---
2 --- Linux + Apache + MySql + PHP5.4 ---
3 --- Linux + Apache + MySql + PHP5.5 ---
--- ---
4 --- PHP UPD 5.3 ---
5 --- PHP UPD 5.4 ---
6 --- PHP UPD 5.5 ---
--- ---
7 --- don't install is now ---
# ------------------------------------
"
sleep 0.1
read -p "Please Input 1,2,3: " Select_Id
if [ $Select_Id == 1 ]; then
#bash $sk/lamp/init.sh
echo 'Linux + Apache + MySql + PHP5.3'
elif [ $Select_Id == 2 ]; then
echo '222222'
else
echo 'no select id, exit...'
exit 1
fi
网友评论