我正在撰寫一個簡短的腳本來自動化輸出檔案名。測驗檔案夾包含以下檔案:
- test_file_1.fa
- test_file_2.fa
- test_file_3.fa
到目前為止,我有以下幾點:
#!/bin/bash
filenames=$(ls *.fa*)
output_filenames=$()
output_suffix=".output.faa"
for name in $filenames
do
output_filenames =$name$output_suffix
done
for name in $output_filenames
do
echo $name
done
這個的輸出是:
test_file_1.fa.output.faatest_file_2.fa.output.faatest_file_3.fa.output.faa
為什么這個回圈將所有檔案名“粘”在一起作為一個陣列變數?
uj5u.com熱心網友回復:
shell 陣列需要特定的語法。
output_filenames=() # not $()
output_suffix=".output.faa"
for name in *.fa* # don't parse `ls`
do
output_filenames =("$name$output_suffix") # parentheses required
done
for name in "${output_filenames[@]}" # braces and index and quotes required
do
echo "$name"
done
https://tldp.org/LDP/abs/html/arrays.html有更多使用陣列的例子。
“不要決議ls” => https://mywiki.wooledge.org/ParsingLs
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/380736.html
