无法解决语法错误:操作数预期(错误标记为“+”)

时间:2014-07-21 17:52:19

标签: bash math

收到此错误,我的代码是:

#!/bin/bash

# argument passed to script (or any other source if needed like intern to script)
file=$1
rs=$2
clin_sig=$3
mut_type=$4
pos=$6
allele=$7
chain_pos=$8
abs_pos=$(($pos+$chain_pos))
echo $abs_pos

其中命令行为:

./program.sh 1 1 1 1 1 1 1
./program.sh: line 11: 1+: syntax error: operand expected (error token is "+")

类似的问题已经使用$(())来解决算术,这对我没用。

2 个答案:

答案 0 :(得分:3)

如果变量为空,则使用默认值

e.g:

pos=${6:-0}
chain_pos=${8:-0}

答案 1 :(得分:0)

$((…))内你省略了变量名前面的$:

abs_pos=$(( pos + chain_pos ))
相关问题