本來不加set什么事兒都沒有(已測試結(jié)果無誤)司忱,加上set -e后就出來問題了:
read_len計算結(jié)果為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
結(jié)果是:
---
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
結(jié)果是:
---
94
結(jié)論:如果設(shè)置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
結(jié)果是:
---
94
tri_len is 0.
~~~~~~
0
0