当前位置:网站首页>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
边栏推荐
- Pytorch中named_parameters、named_children、named_modules函数
- Date date calculation in shell script
- API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
- Calculate the number of occurrences of a character
- 软件性能测试报告起着什么作用?第三方测试报告如何收费?
- 山寨版归并【上】
- 通过 PDO ODBC 将 PHP 连接到 MySQL
- Recommended search common evaluation indicators
- 一刷313-剑指 Offer 06. 从尾到头打印链表(e)
- One brush 313 sword finger offer 06 Print linked list from end to end (E)
猜你喜欢
随机推荐
使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
多生成树MSTP的配置
Extract non duplicate integers
Deeply learn the skills of parameter adjustment
Multitimer V2 reconstruction version | an infinitely scalable software timer
Codejock Suite Pro v20. three
Calculate the number of occurrences of a character
Mumu, go all the way
Connect PHP to MSSQL via PDO ODBC
What are the mobile app software testing tools? Sharing of third-party software evaluation
Treatment of idempotency
pgpool-II 4.3 中文手册 - 入门教程
【Leetcode-每日一题】安装栅栏
Mobile finance (for personal use)
PHP function
Temporal model: long-term and short-term memory network (LSTM)
Upgrade MySQL 5.1 to 5.68
自动化测试框架常见类型▏自动化测试就交给软件测评机构
MySQL集群模式與應用場景
Recommended search common evaluation indicators