avatar
j*s
1
Hi, a short script ,
for loop in `ls incbr* `
do
i=0
while [ $i -lt 8 ]
do
echo $loop
name= awk 'BEGIN {print substr("aab",1,3)}'
echo $name$i
i=`expr $i + 1`
echo $i
done
done
当前目录下有的incbr1, incbr2,incbr3三个文件,所以应该有些3*7次循环,
但是,加上awk这句后,打印完第一个aab和1就象进了死循环.
不知何原因?
大侠帮忙看一下把,谢谢了!!
avatar
a*t
2

this line should be
name=`awk 'BEGIN {print substr("aab",1,3)}'`
but this line seems meaningless, just say name=aab.
you can use 'sh -xv script-name' to debug your script.

【在 j****s 的大作中提到】
: Hi, a short script ,
: for loop in `ls incbr* `
: do
: i=0
: while [ $i -lt 8 ]
: do
: echo $loop
: name= awk 'BEGIN {print substr("aab",1,3)}'
: echo $name$i
: i=`expr $i + 1`

avatar
j*s
3
Thanks a lot!
Another question,
can shell deal with float calculation?
How can I do if I need to deal with divide, which due to float calculation?
Thanks a lot!

【在 a***t 的大作中提到】
:
: this line should be
: name=`awk 'BEGIN {print substr("aab",1,3)}'`
: but this line seems meaningless, just say name=aab.
: you can use 'sh -xv script-name' to debug your script.

avatar
a*t
4

I don't think shell can handle the float. It treats any variable as either
integer or string. You may want to write a c program, or perl script in order
to deal with the float.

【在 j****s 的大作中提到】
: Thanks a lot!
: Another question,
: can shell deal with float calculation?
: How can I do if I need to deal with divide, which due to float calculation?
: Thanks a lot!

avatar
f*r
5
First, in you script, you write: awk 'BEGIB ... ', it's not right. You need to give a
file or stdin as argument, for example: echo $i| awk 'BEGIN ...'
If you want to use float calculation, you can use bc or awk.
Say, you want to calculate: 12./3.4,
then: echo "scale=3; 12./3.4" |bc
or use awk: echo aa | awk 'END {print 12./3.4}' (echo aa is no any meaning, just
give an argument to awk.

【在 j****s 的大作中提到】
: Thanks a lot!
: Another question,
: can shell deal with float calculation?
: How can I do if I need to deal with divide, which due to float calculation?
: Thanks a lot!

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。