文章目录
前言
shell的基本使用
一、变量的使用
1、判断变量是否为空
bash
#!/bin/sh
variable=$(cat /etc/linux.txt | grep "linux")
if [ -z "$variable" ]; then
echo "变量为空"
fi
if [ -n "$variable" ]; then
echo "变量不为空"
fi
2、判断变量是否相等
bash
#!/bin/sh
variable1=$(cat /etc/linux1.txt | grep "linux")
variable2=$(cat /etc/linux2.txt | grep "linux")
if [ "$variable1" = "$variable2" ]; then
echo "变量相等"
else
echo "变量不相等"
fi
3、比较两个整数大小
bash
#!/bin/sh
variable1=2
variable2=1
if [ "$variable1" -gt "$variable2" ]; then
echo "variable1大于variable2"
elif [ "$variable1" -lt "$variable2" ]; then
echo "variable1小于variable2"
else
echo "variable1等于variable2"
fi
二、判断路径是否为空
c
if [ -e /sys/class/gpio ]; then
echo "路径存在"
else
echo "路径不存在"
fi