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";
}
...
}