直接上脚本内容
#!/bin/bash
[ $# -le 0 ] && echo “使用方法 :$0 <滚动频率> <开始时需要显示的行数> <文本文件1的绝对路径> <文本文件2的绝对路径>” && echo “退出按 ctrl+c”&& exit 1
#判断接收的频率参数是否大于0#
if [[
1
=
[
0
−
9
]
∗
1 =~ ^[0-9]*
1= [0−9]∗ ]]
then
if [ $1 -le 0 ]
then
echo “频率得大于0”
exit 1
fi
else
echo “频率参数得为数字”&& exit 1
fi
#判断接收的文件是否存在且可读#
num=0
for i in $*
do
let num+=1
if [ ${num} -gt 2 ];
then
if [ ! -r $i ];
then
echo “文件不存在,请重试 (确认文件是否存在或输入绝对路径)”
exit 1
fi
fi
done
#判断接收的显示行数参数是否大于0#
if [[
2
=
[
0
−
99
]
∗
2 =~ ^[0-99]*
2= [0−99]∗ ]]
then
if [ $2 -le 0 ]
then
echo “开始显示的行数需大于0”
exit 1
fi
else
echo “行数参数得为数字”&& exit 1
fi
touch /tmp/roll.txt
echo “” > /tmp/roll.txt
#持续滚动文件内容#
while true
do
if [ ! -n “$4” ] ;then
cat $3 > /tmp/roll.txt
else
cat $3 $4 > /tmp/roll.txt
fi
echo -n “目标文本总共的行数为:”
sed -n ‘$=’ /tmp/roll.txt
count=1
while read line
do
if [ $count -le
2
]
t
h
e
n
e
c
h
o
"
2 ] then echo "
2]thenecho"count:“
l
i
n
e
e
l
s
e
e
c
h
o
"
line else echo "
lineelseecho"count:”$line
sleep
1
f
i
c
o
u
n
t
=
1 fi count=
1ficount=[ $count + 1 ]
done < /tmp/roll.txt
sleep 1
echo
echo
done
echo “” > /tmp/roll.txt
可在开启一个终端窗口修改文本数据 滚动时会自动更新