LinuxDay3


# 将当前文件目录的内容输出到1.txt
ls > 1.txt

脚本

# test.sh文件内容
# ls
# cal
# date

# 运行脚本
sh test.sh

# echo 输出
a=10
echo $a
echo "Hello World" $a

# 加法
a=10
b=3
c=`expr $a + $b`
echo $c

#乘法需要转义,括号()也要转义
a=10
b=3
c=`expr $a \* $b`
echo $c


# 判断 
# 大于 -gt greater than
# 大于等于 -ge greater equal
# 小于 -lt less than
# 小于等于 -le less equal
# 等于 -eq equal
# 不等于 -ne not equal
a=10
b=3
if [ $a -gt $b ]
then 
	echo $a
else
	echo $b
fi


# 循环
for x in 1 2 3 4 5 6 7 8 9 10 
do
	echo $x
done

# 或者
x=1
while [ $x -le 10 ]
do
	echo $x
	x=`expr $x + 1`
done






Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • 2379. Minimum Recolors to Get K Consecutive Black Blocks
  • 2471. Minimum Number of Operations to Sort a Binary Tree by Level
  • 1387. Sort Integers by The Power Value
  • 2090. K Radius Subarray Averages
  • 2545. Sort the Students by Their Kth Score