当前位置:网站首页>shell_2
shell_2
2022-04-23 15:43:00 【莫迟_】
语法
1. 判断
# [ ] 中间的变量左右保留各保留一个空格
if [ -d $0 ]; then
echo "this is dir"
elif [ -f $0 ]; then
echo "this is file"
else
echo "Nothing"
fi
2. 循环
# seq : sequence: shell的序列,全闭区间
for i in `seq 1 10`
do
echo "current num is $i"
done
等同于:
for ((i=1; i<11; i++)); do echo "current num is $i"; done
3. 函数
foo() {
echo "Hello Shell"
for f in `ls ../`
do
echo $f
done
}
# 调用函数不需要()
foo
注意:
定义函数时,变量名前面加 function 和 不加 function 都可
4. case: 当有有情况符合时执行相应动作语句,否则就退出
cat << EOF
请输入要执行的操作编号:【1-4】
==========================
【1】系统更新
【2】安装软件
【3】安装Redis
【4】安装Nginx
=========================
EOF
# 获取要执行的操作编号
if [[ -n $1 ]]; then
input=$1
echo "执行操作: $1"
else
read -p "请选择: " input
fi
case $input in
1) system_update;;
2) install_software;;
3) install_redis;;
4) install_nginx;;
*) exit;;
esac
版权声明
本文为[莫迟_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_39457834/article/details/124343411
边栏推荐
猜你喜欢
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
Load Balancer
移动金融(自用)
cadence SPB17.4 - Active Class and Subclass
IronPDF for .NET 2022.4.5455
考试考试自用
Configuration of multi spanning tree MSTP
大厂技术实现 | 行业解决方案系列教程
随机推荐
Code live collection ▏ software test report template Fan Wen is here
一刷314-剑指 Offer 09. 用两个栈实现队列(e)
Best practices of Apache APIs IX high availability configuration center based on tidb
c语言---字符串+内存函数
Single architecture system re architecture
Deeply learn the skills of parameter adjustment
Introduction to dynamic programming of leetcode learning plan day3 (198213740)
Explanation 2 of redis database (redis high availability, persistence and performance management)
考试考试自用
What role does the software performance test report play? How much is the third-party test report charged?
PHP function
编译,连接 -- 笔记
Knn,Kmeans和GMM
删除字符串中出现次数最少的字符
WPS品牌再升级专注国内,另两款国产软件低调出国门,却遭禁令
Large factory technology implementation | industry solution series tutorials
C language --- string + memory function
Load Balancer
Control structure (I)
Upgrade MySQL 5.1 to 5.67