执行此脚本后,有时输出如下所示:
1912:! total e
ergy = -1090.13343774 Ry
2310:! total e
ergy = -1090.20757070 Ry
2709:! total e
ergy = -1090.24296462 Ry
3084:! total e
ergy = -1090.25563488 Ry
3483:! total e
ergy = -1090.27085564 Ry
3870:! total e
ergy = -1090.27693129 Ry
4245:! total e
ergy = -1090.28213580 Ry
4632:! total e
ergy = -1090.29131927 Ry
有时像这样:
1912:! total energy = -1090.13343774 Ry
2310:! total energy = -1090.20757070 Ry
2709:! total energy = -1090.24296462 Ry
3084:! total energy = -1090.25563488 Ry
3483:! total energy = -1090.27085564 Ry
3870:! total energy = -1090.27693129 Ry
4245:! total energy = -1090.28213580 Ry
这只是一个错误还是我无意中更改了代码中的某些内容?
代码:
cm=$1
nm=$2
case $cm in
"out")
declare -a en
ec=$(grep -n "! " hw1_out_si_wire.txt)
IFS='\n' en=($ec)
for i in ${en[@]}
do
echo "$i"
done
;;
"in") echo "It's not my problem";;
esac
答案1
IFS='\n'
将内部字段分隔符设置为由两个字符组成:(\
反斜杠)和字母n
。使用IFS=$'\n'
它来设置它只包含换行符。