if 之Python、shell和nginx
if 之Python、shell和nginx
本文输出内容为实现if条件判断,比较Python与shell脚本的不同,实现相同功能不同方法,年轻人方法要多才能灵活解决各种问题,多种方法多条路条条大路通罗马
shell
条件的循环判断,支持elif 和else
# cat score.sh #!/bin/bash read -p '请输入分数:' score echo ${score} if [ ${score} -ge 90 ];then echo '优秀' elif [ ${score} -ge 80 ];then echo '良好' elif [ ${score} -ge 70 ];then echo '普通' else echo '不及格' fi
# bash score.sh
请输入分数:99
99
优秀
Python
条件的循环判断,支持elif 和else
# cat score.py #!/bin/python3 score=input('请输入分数:') score=int(score) if score >= 90: print('优秀') elif score >= 80 and score < 90: print('良好') elif score >=70 and score < 80: print ('普通') else: print('不及格') # python3 score.py 请输入分数:99 优秀 # python3 score.py 请输入分数:88 良好 # python3 score.py 请输入分数:77 普通
nginx
针对请求的uri是txt或text内容,那么久不会缓存,这里是一个判断如果是符合条件就执行,不存在else或elif,可用于页面缓存或者请求返回内容
server { listen 80; server_name cache.lion.club; # URI 中后缀为 .txt 或 .text 的设置变量值为 "no cache" if ($request_uri ~ \.(txt|text)$) { set $cache_name "no cache"; } ... }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)