#!/bin/bash
#
read -p "Please input two files: " FILE1 FILE2
if ! cat $FILE1 &> /dev/null ; then
echo "please enter the first true path file"
exit 5
if ! cat $FILE2 &> /dev/null ;then
echo "please enter the second true path file"
exit 5
fi
fi
LINE1=$(cat $FILE1 | wc -l )
LINE2=$(cat $FILE2 | wc -l )
if [ $LINE1 -ne $LINE2 ] ; then
if [ $LINE1 -gt $LINE2 ] ; then
echo "$FILE1"
else
echo "$FILE2"
fi
else
echo "$FILE1 and $FILE2 are generally long"
fi
unset FILE1 FILE2 LINE1 LINE2
3.利用RANDOM变量随机生成十个数字,显示出这十个数字,并显示出其中的最大值和最小值。
#!/bin/bash
#
touch /tmp/math.txt
for I in $(seq 1 10) ; do
J=$RANDOM
echo "$J "
echo "$J" >> /tmp/math.txt
done
K=$( sort -n /tmp/math.txt | head -1)
L=$( sort -n /tmp/math.txt | tail -1)
echo "laster $L ; leaster $K "
rm -rf /tmp/math.txt
exit 5
4.给脚本传递一个数字作为行总数,分别打印由*组成的最0小锐角朝上和朝下的等腰三角形以及菱形。
#!/bin/bash
#
read -p "enter one number: " INT
if [[ $INT =~ [^[:digit:]] ]] ; then
echo "please enter the number"
exit 5
fi
echo ”zheng sanjiao“
for I in $(seq $INT) ; do
for J in $(seq $[INT-I]) ; do
echo -n " "
done
for K in $(seq $[2*I-1]) ; do
echo -n "*"
done
echo
done
echo "dao sanjiao"
for M in $(seq $INT) ; do
for B in $(seq $[M-1]) ; do
echo -n " "
done
for N in $(seq $[2*(INT-M)+1]) ; do
echo -n "*"
done
echo
done
echo "lingxing"
if [ $[INT%2] -ne 0 ] ; then
INT2=$[(INT+1)/2]
for Q in $(seq $INT2) ; do
for W in $(seq $[INT2-Q]) ; do
echo -n " "
done
for E in $(seq $[2*Q-1]) ; do
echo -n "*"
done
echo
done
for R in $(seq $[INT2-1]) ; do
for T in $(seq $[R]) ; do
echo -n " "
done
for Y in $(seq $[2*(INT2-R)-1]) ; do
echo -n "*"
done
echo
done
exit 7
else
echo "qing shuru jishu >3"
fi
5.分别打印顺序和旋转的九九乘法表。
顺序的九九乘法表是正常的九九乘法表;
旋转的九九乘法表是第一行是1×1=1 1×2=2 1×3=3 1×4=4 ... 1×9=9; 第二行是2×2=4 2×3=6 2×4=8 ... 2×9=18; ... 第九行是9×9=81;
#!/bin/bash
#
for I in $(seq 1 9) ; do
for J in $(seq 1 $I) ;do
echo -ne "$I×$J=$[I*J]\t"
done
echo
done
for M in $(seq 1 9) ; do
for N in $(seq $M 9) ; do
echo -ne "$M×$N=$[N*M]\t"
done
echo
done