0
我有我希望能轉換成一個for循環下面簡單的代碼:奇怪的回聲行爲瓦爾
i="1"; \
plate="$(grep -P "^${i}" SampleIDs-Nov9-gyrA_S1-2.tab | cut -f 2)"; \
plateid="$(grep -P "^${i}" SampleIDs-Nov9-gyrA_S1-2.tab | cut -f 3)"; \
strain="$(grep -P "^${i}" SampleIDs-Nov9-gyrA_S1-2.tab | cut -f 4)"; \
replicate="$(grep -P "^${i}" SampleIDs-Nov9-gyrA_S1-2.tab | cut -f 5)"; \
timepoint="$(grep -P "^${i}" SampleIDs-Nov9-gyrA_S1-2.tab | cut -f 6)"; \
medium="$(grep -P "^${i}" SampleIDs-Nov9-gyrA_S1-2.tab | cut -f 7)"; \
total="$(awk -F'\t' 'BEGIN{n=0}{ n++ }END{print n/4}' ../trial1_merged_dir/${i}.extendedFrags.fastq)"; \
mut="$(grep -P "^${strain}" mutants-short.unix.txt | awk '{print toupper($2)}')"; \
wt="$(grep -P "^${strain}" mutants-short.unix.txt | awk '{print toupper($3)}')"; \
mutc="$(grep -c $mut ../trial1_merged_dir/${i}.extendedFrags.fastq)"; \
wtc="$(grep -c $wt ../trial1_merged_dir/${i}.extendedFrags.fastq)"; \
echo $i; \
echo $strain; \
echo $medium; \
echo $replicate; \
echo $timepoint; \
echo $wtc; \
echo $mutc; \
echo $total; \
輸出:
1
cip1
M9_Glucose
1
T0
4794
2938
9289
這是正常的。然而,當我與一個取代最後8行回聲:
echo "$strain $i $medium $replicate $timepoint $wtc $mutc $total"; \
輸出:
1 T0 4794 2938 9289
不正常。我想知道有什麼可能導致一些價值觀的藥房?
還有一次,我嘗試了,我得到這個輸出:
1 1ip1 T0_Gluco4794 2938 9289
更爲離奇的是一些文本融合,結果被截斷。
什麼是所有的反斜槓? – chepner
'; 「在行尾沒有任何意義。行尾的'\'告訴shell下一行是這個行的延續,但是'''本質上就是將行後面的行作爲單獨行。他們相互取消了!把它們都關掉。另外,你應該總是在變量引用周圍放置雙引號,如'grep -c「$ mut」'和'echo「$ i」'。我總是推薦[shellcheck.net](http://www.shellcheck.net)開始編寫腳本,因爲它會指出代碼中的常見錯誤。 –