返回顶部

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";
  }
  ...
}
复制代码

 

posted @   九尾cat  阅读(52)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)

目录导航

点击右上角即可分享
微信分享提示