[英]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.