如何在shell脚本中只添加正数?

如何在shell脚本中只添加正数?,shell,sum,Shell,Sum,另外,请参阅了解更多bash脚本编写指南。shell执行两种比较测试:字典(字符串)和数字。词典学的有=,,,认为-2大于0,因为-和0在字符集中的相对位置。数字的那一个,-gt,从算术的角度理解减号 因此,如果[$number>0],则行不符合您的要求 manbash解释如下: string1=string2 如果字符串相等,则为True。=应与POSIX一致性测试命令一起使用。 string1!=string2 如果字符串不相等,则为True。 string1string2 如果string

另外,请参阅了解更多bash脚本编写指南。

shell执行两种比较测试:字典(字符串)和数字。词典学的有
=
,认为
-2
大于
0
,因为
-
0
在字符集中的相对位置。数字的那一个,
-gt
,从算术的角度理解减号

因此,如果[$number>0],则行
不符合您的要求

manbash
解释如下:

string1=string2
如果字符串相等,则为True。=应与POSIX一致性测试命令一起使用。
string1!=string2
如果字符串不相等,则为True。
string1string2
如果string1按字典顺序在string2之后排序,则为True
arg1 OP arg2
OP是-eq、-ne、-lt、-le、-gt或-ge中的一个。如果arg1等于,
分别不等于、小于、小于或等于、大于或大于或等于arg2。
Arg1和arg2可以是正整数或负整数。

如果您还包括对您在此处尝试执行的操作以及
$file
的内容的详细描述,则会有所帮助。
sum=0
for file in $*
do
  for number in `grep -wo "[0-9]*" $file`
  do
    if [ $number > 0 ]
    then
        sum=$(($sum+numar))
    fi
  done
done
echo "Suma este: $sum"
if [[ $number -gt 0 ]];
$ [ -2 > 0 ] && echo yes
yes
$ [ -2 -gt 0 ] && echo yes
   string1 = string2
          True if the strings are equal.  = should be used with the test command for POSIX conformance.

   string1 != string2
          True if the strings are not equal.

   string1 < string2
          True if string1 sorts before string2 lexicographically.

   string1 > string2
          True if string1 sorts after string2 lexicographically

   arg1 OP arg2
          OP is one of -eq, -ne, -lt, -le, -gt, or -ge.  These arithmetic binary operators return true if arg1 is equal  to,
          not  equal  to,  less  than,  less than or equal to, greater than, or greater than or equal to arg2, respectively.
          Arg1 and arg2 may be positive or negative integers.