发表于 : 2008-08-18 22:51
空格先转义? 

仍然不行滴HuntXu 写了:空格先转义?
代码: 全选
lonelycorn@untbook:~$ cat abc
lkjlksdf lkjsdlkfj dfjlkjwelr
lkjsd jklerjncvlkj this sucks!!
sldkjflkwe sdjlkj
sdfljk xlkcjlsf
lskdjfl saldkfjl adfl
lonelycorn@untbook:~$ cat xxx
#!/bin/bash
exec 10<&0
exec < abc
n=0
while read arr[`expr $n + 1 `]
do
let n+=1
read arr[${n}]
done
exec 0<&10 10<&-
for (( i=0; i<${#arr[@]}; i++ ));do echo ${arr[${i}]}; done
lonelycorn@untbook:~$ ./xxx
lkjsd jklerjncvlkj this sucks!!
sdfljk xlkcjlsf
代码: 全选
lonelycorn@untbook:~$ cat abc
lkjlksdf lkjsdlkfj dfjlkjwelr
lkjsd jklerjncvlkj this sucks!!
sldkjflkwe sdjlkj
sdfljk xlkcjlsf
lskdjfl saldkfjl adfl
lonelycorn@untbook:~$ cat xxx
#!/bin/bash
declare -a arr
exec 10<&0
exec < abc
n=0
while read arr[$(( $n + 1 ))]
do
let n+=1
done
exec 0<&10 10<&-
echo ${#arr[*]}
for (( i=0; i<${#arr[@]}; i++ ));do echo ${arr[${i}]}; done
lonelycorn@untbook:~$ ./xxx
6
lkjlksdf lkjsdlkfj dfjlkjwelr
lkjsd jklerjncvlkj this sucks!!
sldkjflkwe sdjlkj
sdfljk xlkcjlsf
lskdjfl saldkfjl adfl
代码: 全选
lonelycorn@untbook:~$ cat abc
lkjlksdf lkjsdlkfj dfjlkjwelr
lkjsd jklerjncvlkj this sucks!!
sldkjflkwe sdjlkj
sdfljk xlkcjlsf
lskdjfl saldkfjl adfl
lonelycorn@untbook:~$ cat xxx
#!/bin/bash
declare -a arr
exec 10<&0
exec < abc
n=0
while read arr[$n]
do
let n+=1
done
unset arr[$n]
exec 0<&10 10<&-
echo ${#arr[*]}
for (( i=0; i<${#arr[@]}; i++ ));do echo ${arr[${i}]}; done
lonelycorn@untbook:~$ ./xxx
5
lkjlksdf lkjsdlkfj dfjlkjwelr
lkjsd jklerjncvlkj this sucks!!
sldkjflkwe sdjlkj
sdfljk xlkcjlsf
lskdjfl saldkfjl adfl
代码: 全选
$ cat file |while read line; do echo "${line}";done
不明白。说详细一点。或者举个例子。
我逗无 了奈了……
HP的本跑 ubuntu还得把我折腾死。
显卡、无线/ 有线网卡、声卡、键盘……
成功复活~
代码: 全选
#!/bin/bash
[ -z $1 ] && echo "No input file!" && exit 1
screen_line=${2:-10}
line_width=${3:-80}
(( hlt_line = screen_line / 2 ))
mk_lines() {
OIFS=$IFS
echo $OIFS
IFS="
"
lines=($(cat $1 | fold -w $line_width))
IFS=$OIFS
line_cnt=${#lines[@]}
}
init() {
tty=$(stty -g)
echo -e "\033[?25l"
}
restore() {
echo -e "\033[?25h"
stty $tty
clear
}
show() {
local num index
clear
for ((num=0; num<screen_line; num++)); do
(( index = $1 - hlt_line + num))
if (( index < 0 )) || (( index >= line_cnt)); then
continue
fi
echo -ne "\033[$((num+3));10H"
if (( num == hlt_line )); then
echo -ne "\033[;32m${lines[$index]}\033[0m"
else
echo -ne "${lines[$index]}"
fi
done
}
##########################################################
mk_lines $1
init
for ((i=0; i<line_cnt; i++)); do
show $i
sleep 1
done
restore