Linux简单脚本编写

2025-01-02 13:30:12
推荐回答(2个)
回答1:

2、

#!/bin/bash
while read LINE
do
ass="$ass$LINE"
case $LINE in
EOF) exit ;;
esac
echo "$ass"
done

4、
#!/bin/bash
_type1=`file $1 | cut -d" " -f2-`
_type2=`file $2 | cut -d" " -f2-`
_time1=`ls -l $1 | awk '{print $6,$7,$8}'`
_time2=`ls -l $2 | awk '{print $6,$7,$8}'`

test -f $1 && test -f $2 && [ "${_type1}" = "${_type2}" ] && find -perm 644 | grep -E "$1|$2" >/dev/null 2>&1

if [ $? = 0 ];then
if test $1 -nt $2 ; then
cp $1 /tmp && echo "Copy is ok"
fi
if test $2 -nt $1 ; then
cp $2 /tmp && echo "Copy is ok"
fi
if [ "${_time1}" = "${_time2}" ];then
echo "The time of two files is as well."
fi
else
echo "File is different."
fi

回答2:

3、
#!/bin/bash

operator="+ - x / exit"
echo -n "please input two digits:"
read number1 number2
echo number is: $number1 $number2
select i in $operator
do
case $i in
+)result=$(($number1+$number2));
echo "The result is:$result";;
-)result=$(($number1-$number2));
echo "The result is:$result";;
x)result=$(($number1 * $number2));
echo "The result is:$result";;
/)result=$(($number1 / $number2));
echo "The result is:$result";;
exit)
echo "bye";exit;;
esac
done