You must have seen the effect of flying words on a Web page, but how do you implement the Echo string in a Linux system, especially in Bash command line mode, with flying effects?
This effect is not practical, but occasionally to amuse themselves or show off a good way, oh, the following to a section of shell script code to explain how to achieve ...
#!/bin/bash [Z $] && echo "Input is invalid!" && exit 1 txt= ($ (Cat $1|sed ' s/\+/_/g ') lines=${ #txt [@]} max_show=10 #最多显示行数 (more than the total number of rows) [${max_show}-gt ${lines}] && Max_show=${lines} hlt_line=3 #高亮显示 Location (no more than row 1/2, set to 3 is actually line 4th) [${hlt_line}-GT $ ((LINES/2))] && hlt_line=$ ((LINES/2)) stty=$ (stty-g) #保存终端设 Place clear Echo-ne "\033[?25l" #隐藏光标 spaces () {local i J n i=0; n=0 for ((j=0; j <= ${lines}; j +));d o [$i- Lt ${#txt [$j]}] && ((i = ${#txt [$j]})) && ((n = $j)) done echo ${txt[$n]}|sed ' s/.//g '} _line=$ (spaces) #传递的参数是欲显示行的序数: Show 1 shows the first line highlighting display () {Local I J-text Crt_line j=$1 for (i=0; i < max_show; i++);d o crt_line=$ ((j + i-hlt_line)) if [$i-eq ${hlt_line}] && [${crt_line}-ge 0] && [${crt _line}-le ${lines}];then text= "\033[;32m" ${txt[${crt_line}]} "\033[0m" Elif [${crt_line}-lt 0] | | [${crt_line}-gt ${lines}];then text=${Space_line} else Text=${txt[${crt_line}] fi Echo-ne "\033[$ ((i+3)); 0h${space_line}" Echo-ne "\033[$ ((i+3)); 6H${tex T} ' done} ' #测试 for ((j = 0; J < lines + Hlt_line +1; j +));d o show $j sleep 1 done
To restore the default settings method:
echo ""
stty ${stty} #恢复终端设置
echo-e "\033[?25h\033[0;0h" #恢复光标