2016-06-20 5 views
0

bash의 파일명이인 경우 입력을 요구하는 메시지가 표시되면 select에서 사용할 파일을 묻는 메시지가 나타납니다. 그러나 디렉토리에 3 개가 있지만 표시된 파일은 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의 출력은 줄 바꿈으로 구분됩니다.

select 이전의 이전 값 (IFS=$OLDIFS)으로 복원해야합니다.

또한, 내가 대신 목록의 서브 쉘의 출력의 globing 쉘을 사용하는 것이 좋습니다 것입니다 : 당신이 OLDIFS에 IFS 값을 저장하지만 당신이 그것을 복원하지 않았다처럼

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

감사와 설명 모두에 감사드립니다. 감사합니다 :). – Chris

2

이 보인다. select 명령에서 사용하는 확장은 IFS가 기본값으로 복원되어야합니다.

관련 문제