💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## if 判断一个文件是否存在 ``` [ -f /etc/passwd ] && echo "yes" || echo "no" ``` 判断一类文件(*.c)是否存在 ``` [ $(ls *.c 2> /etc/null) ] && echo "yes" || echo "not" ``` 判断一个文件是否存在(脚本) ``` #!/bin/bash if [ -f /etc/passwd ]; then echo "there" else echo "not there" fi ``` 判断远程服务器端口是否通 ``` #!/bin/bash nc -zv www.baidu.com 80 &> /dev/null if [ $? -eq 0 ] then echo "up" else echo "down" fi ``` 自定义 ``` #!/bin/bash result="fail" if [ $result == "success" ] then echo "success" else echo "fail" fi ``` 与 或 ``` if [[ $a != 1 && $a !=2 ]] if [[ $a != 1 || $a !=2 ]] ``` ## case case案例 ``` #!/bin/bash read -p "Please enter your city:" your_city echo -n "The prefix phone number of $your_city is " case $your_city in Beijing | BEIJING | beijing) echo "010" ;; Shanghai | SHANGHAI | shanghai) echo "021" ;; Shenzhen | SHENZHEN | shenzhen) echo "0755" ;; *) echo "to be continued..." ;; esac ```