1.比较两个数大小
#/bin/bash
echo "please enter two number"
read a
read b
if test $a -eq $b
then echo "NO.1 = NO.2"
elif test $a -gt $b
then echo "NO.1 > NO.2"
else echo "NO.1 < NO.2"
fi
输出结果:
3.查找/root/目录下是否存在该文件
#/bin/bash
echo "enter a file name:"
read a
if test -e /root/$a
then echo "the file is exist!"
else echo "the file is not exist!"
fi
输出结果:
4.for循环的使用
#/bin/bash
clear
for num in 1 2 3 4 5 6 7 8 9 10
do
echo "$num"
done
输出结果:
5.命令行输入
#/bin/bash
echo "Please enter a user:"
read a
b=$(whoami)
if test $a = $b
then echo "the user is running."
else echo "the user is not running."
fi
输出结果:
6.从0.sh中读取内容并打印
#/bin/bash
while read line
do
echo $line
done < 0.sh
输出结果:
7.打印当前用户
#/bin/bash
echo "Current User is :"
echo $(ps | grep "$$" | awk '{print $2}')
输出结果: