【发布时间】:2011-11-28 19:39:52
【问题描述】:
这是我的 bash 代码的一部分;
b=`cat 101127_2_aa_1.fastq|head -$a|tail -1|sed 's/\(.\)B*$/\1/g'|wc -c`
d=`cat 101127_2_aa_1.fastq|head -$a|tail -1|wc -c`
if (($b%$d>=0.7))
then
但是我遇到了这样的问题:
line 13: ((: 26%100>=0.7: syntax error: invalid arithmetic operator (error token is ".7")
有什么问题? 谢谢
编辑: 我的脚本中有两个 if 循环:
if (($a%4==0))
if (( 10*$b/$d>= 7 ))
似乎是第一个,只有“%”有效
对于第二个,只有“/”有效
我很困惑
【问题讨论】:
-
thx....但是我该怎么办?
-
您是要取模,还是要除法并弄乱运算符?如果取模,那么你最好描述你在做什么,在浮点数上使用模...... :) 你的变量名无助于易读性。如果是你想要的除法,那么
($b*10)/$d>=7应该可以工作。 -
是的,除法是我想要的。但是,当使用 if (($a%4)) 时,效果很好。我的意思是“%”与“/”,我应该使用哪一个?
-
好吧,除法是
/:echo $((200/3))给66。%是模(除法的余数),所以echo $((200%3))给出2(因为 200 = 66 * 3 + 2)。两者在bash中都是语法,但它们做的事情截然不同。
标签: bash floating-point divide