本来不加set什么事儿都没有(已测试结果无误),加上set -e后就出来问题了:
read_len计算结果为94
set -e
正常情况下
set -e
read_len=`zcat demo.fq.gz | head -n 2 | tail -1 | wc -L`
# || echo "read len"
echo "---"
echo $read_len
tri_len=`expr $read_len - 98`
#|| echo "tri_len is 0."
echo "~~~~~~"
echo $tri_len
if [ $tri_len -lt 0 ]; then tri_len=0 && echo "--------"; fi
echo $tri_len
结果是:
---
94
~~~~~~
-4
--------
0
expr表达式计算中98改为94(tri_len值为0)
set -e
read_len=`zcat demo.fq.gz | head -n 2 | tail -1 | wc -L`
# || echo "read len"
echo "---"
echo $read_len
tri_len=`expr $read_len - 94`
#|| echo "tri_len is 0."
echo "~~~~~~"
echo $tri_len
if [ $tri_len -lt 0 ]; then tri_len=0 && echo "--------"; fi
echo $tri_len
结果是:
---
94
结论:如果设置set -e 则遇到解析后值为零的变量会退出脚本(但tri_len值确是有的,为0),可以通过||符号来改变**,或者干脆不要加set -e了。
set -e
read_len=`zcat 200901_R1100600190007_E100005555_L001_HUMM200026313BCDANGC1AA-4556-cd3_1.fq.gz | head -n 2 | tail -1 | wc -L`
# || echo "read len"
echo "---"
echo $read_len
tri_len=`expr $read_len - 94` || echo "tri_len is $tri_len."
echo "~~~~~~"
echo $tri_len
if [ $tri_len -lt 0 ]; then tri_len=0 && echo "--------"; fi
echo $tri_len
结果是:
---
94
tri_len is 0.
~~~~~~
0
0