簡體   English   中英

bash輸入輸入並選擇文件

[英]bash to enter input and select file

ubuntu 14.04的下面bash提示用戶輸入,然后要求用戶在select使用該文件。 但是,我只能選擇其中一個文件,因為盡管目錄中有3個文件,但只有1個文件被標記。 但是,如果我將select文件放在輸入之前, bash似乎可以工作。 我似乎無法解決它,怎么了? 謝謝。

重擊

# enter gene input
printf "%s \n" "Please enter gene(s), use a comma between multiple:"
OLDIFS=$IFS
IFS=","
read -a genes
for (( i = 0; i < ${#genes[@]}; i++ ))
do
printf "%s\n" "${genes[$i]}" >> /home/cmccabe/Desktop/NGS/panels/GENE.bed
done

# select file
printf "please select a file to analyze with entered gene or genes  \n"
select file in $(cd /home/cmccabe/Desktop/NGS/API/test/bedtools;ls);do break;done
        echo $file "will be used to filter reads, identify target bases and genes less than 20 and 30 reads, create a low coverage bed for vizulization, and calculate 20x and 30x coverage for the entered gene(s)"
logfile=/home/cmccabe/Desktop/NGS/API/test/process.log
for file in /home/cmccabe/Desktop/NGS/API/test/bedtools/$file; do
 echo "Start selcted file creation: Panel: ${FUNCNAME[0]} Date: $(date) - File: $file"
 bname=$(basename $file)
 pref=${bname%%.txt}
 echo "End selected file creation: $(date) - File: $file"
 done >> "$logfile"

顯示在終端

1) 12_newheader_base_counts.txt
   34_newheader_base_counts.txt
   56_newheader_base_counts.txt

所需的終端顯示

1) 12_newheader_base_counts.txt
2) 34_newheader_base_counts.txt
3) 56_newheader_base_counts.txt

的的修改IFS事先打破的方式select考慮您的目錄列表:與IFS=,它現在正在尋找通過分離項目,同時您的ls的輸出由線分開飼料。

select之前,應將IFS還原為其先前的值( IFS=$OLDIFS )。

另外,我建議使用外殼gloglo而不是列表子shell的輸出:

select file in /home/cmccabe/Desktop/NGS/API/test/bedtools/*;

似乎您已將IFS值保存到OLDIFS,但隨后沒有還原它。 在select命令中使用的擴展要求將IFS恢復為其默認值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM