2016-06-20 4 views
0

bashをに入力すると、ユーザに入力を促してから、selectで使用するファイルを要求します。しかし、ディレクトリに3つありますが、マークされているのは1つだけなので、ファイルの1つしか選択できません。しかし、入力前にselectファイルを置くと、bashが動作するようです。私はそれを修正するように見えない、何が間違っている?ありがとう。bashを入力してファイルを選択する

端末

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

に表示バッシュ

# 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 
2) 34_newheader_base_counts.txt 
3) 56_newheader_base_counts.txt 
+1

また、http://www.shellcheck.net/でスクリプトをコピーして、スクリプト内のすべてのpit-fallを修正することをお勧めします。些細な問題のためにあなたの貴重な時間を節約することができます – Inian

答えて

3

既にIFSの変更により、はあなたのディレクトリリストを考慮する方法を破ります:IFS=,で、,で区切られた項目を探していますが、lsの出力は改行で区切られています。

IFSselectより前の以前の値(IFS=$OLDIFS)に復元する必要があります。

また、私は上場サブシェルの出力の代わりにglobingシェルを使用することをお勧めします:

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

あなたの助けと説明の両方に非常に感謝します。 – Chris

2

あなたはOLDIFSにIFS値を保存したが、その後、あなたがそれを回復しなかったように思えます。 selectコマンドで使用する拡張では、IFSをデフォルト値に戻す必要があります。

関連する問題