我有一次看到有人在壳里做这个。我有一个.txt文件,我想逐行显示,这样就可以用击键进入下一行。文本的大小也可以更改。
我的档案是这样的
001: hello world.
002: hello kitty
003: the cat in the hat我希望bash只展示:
001: hello world.在一个大字体中,它可以像提词器一样读取,并且用箭头键或"n“键显示:
002: hello kitty以同样的方式。
也许我在做梦,但我很确定这是用shell脚本完成的。
发布于 2016-03-06 21:06:45
像这样的事怎么样:
#!/bin/bash
temp=
exec 10<&0
while read line || [ -n "$line" ]
do
echo "$line"
while true
do
read -s -u 10 -n 1 temp
clear
[[ $temp =~ ^n$ ]] && break
done
done < "file"输出:
$ chmod 755 script.bash
$ cat file
001: hello world.
002: hello kitty
003: the cat in the hat
$ ./script.bash
001: hello world.
002: hello kitty
003: the cat in the hat
$注意:您可以使用'n‘键转到下一行。
说明:第一,使用exec 10<&0,我将标准输入0(键盘)复制到另一个文件描述符10,即键盘输入现在通过10而不是默认的0提供给我们的程序。
然后,我只需逐行读取文件,并打印每一行。打印完每一行后,我使用read命令暂停用户输入,read等待1 char用户输入(-n 1)并从键盘(-u 10)读取,因为默认的stdin fd 0现在指向file。一旦一个键被读取,它就会使用regex检查它是否是'n‘,如果是,它会从无限循环中分离出来,如果不是,它会再次循环,直到用户输入'n’为止。
至于改变字体大小,这是非常特定于您的发行版/终端。为此,您可以使用setfont命令。更多信息可以在这里找到:https://askubuntu.com/questions/29328/how-do-i-increase-the-text-size-of-the-text-on-a-console和http://www.linuxquestions.org/questions/linux-newbie-8/bash-font-size-831366/
https://stackoverflow.com/questions/35832181
复制相似问题