简单shell命令(三)

104 阅读1分钟

本文已参与新人创作礼活动,一起开启掘金创作指路。

Shell 流程控制

1.if else elif

#!/bin/bash
demo='1'
num='2'
if [ $demo == $num ]
then
 echo "demo和num相等"
else
echo "不相等"
fi

结果

不相等

2.for循环

#!/bin/bash
for loop in 1 2 3 4 5
do
    echo "The value is: $loop"
done

结果

The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5

3、while

#!/bin/bash
int=1
while(( $int <=5 ))
do
	echo "$int"
	let "int++"
done

结果

1
2
3
4
5

4.if和while合并使用

	#!/bin/bash
	echo -n '输入作者的名字: '
	while read FILM
	do
		if [ $FILM == "seaiio" ]
		then
		echo "是的!$FILM 是作者!"
		else
		echo "$FILM 不是作者!"
		fi
	done

	

结果 在这里插入图片描述