简体   繁体   English

简单的unix shell循环

[英]Simple unix shell loop

So I am very new to unix coding and I have a fairly simple task that I just can't seem to figure out. 因此,我对UNIX编码非常陌生,而且我有一个相当简单的任务,我似乎无法弄清楚。

I have a folder on my desktop with multiple .fq files ( Desktop/btindex ), and I am looking for a way to iterate over just those files in a shell script, and call commands on them. 我的桌面上有一个文件夹,其中包含多个.fq文件( Desktop/btindex ),我正在寻找一种方法来遍历shell脚本中的那些文件,并在它们上调用命令。 I just can't seem to find the right syntax to do this. 我似乎找不到正确的语法来做到这一点。

Is it best to write this script in an editor like vim from the console? 最好从控制台通过vim之类的编辑器编写此脚本吗? Or is it better to just write it all out in the console itself? 还是将其全部写入控制台本身会更好吗?

Edit: I am working in the directory Desktop/bwaout, so my code: 编辑:我正在目录Desktop / bwaout,所以我的代码:

for file in '../btindex/*.fq';
do
    echo $file
done

seems to print... 似乎打印...

../btindex/X.fq

How do I just get the .fq to print? 我如何才能打印出.fq?

Use a for loop as shown below: 使用如下所示的for循环:

for file in /some/path/*.fq
do
    echo "Processing file: $file"
    # other commands here    
done
for myfile in *.fq ; do command "$myfile" ; another_command "$myfile" ; done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM