Shell 脚本未运行,未找到命令 [英] Shell script not running, command not found

查看:135
本文介绍了Shell 脚本未运行,未找到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 UNIX 编程非常非常陌生(通过终端在 MacOSX Mountain Lion 上运行).我一直在学习生物信息学和分子方法课程的基础知识(我们有两节课),我们最终将使用 perl 和 python 进行数据管理.无论如何,我们的任务是编写一个 shell 脚本来从一组文件中获取数据,并将其以特定程序 (Migrate-N) 可以读取的格式写入新文件.

I am very, very new to UNIX programming (running on MacOSX Mountain Lion via Terminal). I've been learning the basics from a bioinformatics and molecular methods course (we've had two classes) where we will eventually be using perl and python for data management purposes. Anyway, we have been tasked with writing a shell script to take data from a group of files and write it to a new file in a format that can be read by a specific program (Migrate-N).

当我在命令行中输入它们时,我已经获得了许多函数来独立完成我需要的功能,但是当我将它们全部放在一个脚本中并尝试运行它时,我得到了一个错误.以下是详细信息(对于篇幅我深表歉意):

I have gotten a number of functions to do exactly what I need independently when I type them into the command line, but when I put them all together in a script and try to run it I get an error. Here are the details (I apologize for the length):

#! /bin/bash

grep -f Samples.NFCup.txt locus1.fasta > locus1.NFCup.txt
grep -f Samples.NFCup.txt locus2.fasta > locus2.NFCup.txt
grep -f Samples.NFCup.txt locus3.fasta > locus3.NFCup.txt
grep -f Samples.NFCup.txt locus4.fasta > locus4.NFCup.txt
grep -f Samples.NFCup.txt locus5.fasta > locus5.NFCup.txt
grep -f Samples.Salmon.txt locus1.fasta > locus1.Salmon.txt
grep -f Samples.Salmon.txt locus2.fasta > locus2.Salmon.txt
grep -f Samples.Salmon.txt locus3.fasta > locus3.Salmon.txt
grep -f Samples.Salmon.txt locus4.fasta > locus4.Salmon.txt
grep -f Samples.Salmon.txt locus5.fasta > locus5.Salmon.txt
grep -f Samples.Cascades.txt locus1.fasta > locus1.Cascades.txt
grep -f Samples.Cascades.txt locus2.fasta > locus2.Cascades.txt
grep -f Samples.Cascades.txt locus3.fasta > locus3.Cascades.txt
grep -f Samples.Cascades.txt locus4.fasta > locus4.Cascades.txt
grep -f Samples.Cascades.txt locus5.fasta > locus5.Cascades.txt

echo 3 5 Salex_melanopsis > Smelanopsis.mig
echo 656 708 847 1159 779 >> Smelanopsis.mig
echo 154 124 120 74 126 NFCup >> Smelanopsis.mig
cat locus1.NFCup.txt locus2.NFCup.txt locus3.NFCup.txt locus4.NFCup.txt locus5.NFCup.txt >> Smelanopsis.mig
echo 32 30 30 18 38 Salmon River >> Smelanopsis.mig
cat locus1.Salmon.txt locus2.Salmon.txt locus3.Salmon.txt locus4.Salmon.txt locus5.Salmon.txt >> Smelanopsis.mig
echo 56 52 24 29 48 Cascades >> Smelanopsis.mig
cat locus1.Cascades.txt locus2.Cascades.txt locus3.Cascades.txt locus4.Cascades.txt locus5.Cascades.txt >> Smelanopsis.mig

这一系列 grep 只是将每个位点的每个位点的 DNA 序列数据提取到新的文本文件中.Samples...txt 文件具有站点的样品 ID 号,.fasta 文件具有按样品 ID 组织的序列信息;如果我单独运行它,grepping 在命令行中工作得很好.

The series of greps are just pulling out DNA sequence data for each site for each locus into new text files. The Samples...txt files have the sample ID numbers for a site, the .fasta files have the sequence information organized by sample ID; the grepping works just fine in command line if I run it individually.

第二组代码创建了我最终需要的实际新文件,以 .mig 结尾.回波线是有关计数的数据(每个位点的碱基对、分析中的种群、每个位点的样本等),程序需要这些信息.cat 行将根据回声行中指定的站点特定信息下方的所有 grepping 创建的站点数据将轨迹混合在一起.你无疑得到了图片.

The second group of code creates the actual new file I need to end up with, that ends in .mig. The echo lines are data about counts (basepairs per locus, populations in the analysis, samples per site, etc.) that the program needs information on. The cat lines are to mash together the locus by site data created by all the grepping below the site-specific information dictated in the echo line. You no doubt get the picture.

为了创建 shell 脚本,我一直在 Excel 中开始,因此我可以轻松地复制粘贴/自动填充单元格,保存为制表符分隔的文本,然后在 TextWrangler 中打开该文本文件以在保存为 .sh 之前删除制表符文件(换行符:Unix (LF) 和编码:Unicode (UTF-8))与脚本中使用的所有文件位于同一目录中.我尝试使用 chmod +x FILENAME.shchmod u+x FILENAME.sh 来尝试确保它是可执行的,但无济于事.即使我将脚本缩减为一个 grep 行(带有 #!/bin/bash 第一行),我也无法让它工作.当我直接在命令行中输入它时,这个过程只需要一点时间,因为这些文件都没有大于 160KB,有些文件要小得多.这是我输入的内容以及尝试运行文件时得到的内容(HW 是正确的目录)

For creating the shell script I've been starting in Excel so I can easily copy-paste/autofill cells, saving as tab-delimited text, then opening that text file in TextWrangler to remove the tabs before saving as a .sh file (Line breaks: Unix (LF) and Encoding: Unicode (UTF-8)) in the same directory as all the files used in the script. I've tried using chmod +x FILENAME.sh and chmod u+x FILENAME.sh to try to make sure it is executable, but to no avail. Even if I cut the script down to just a single grep line (with the #! /bin/bash first line) I can't get it to work. The process only takes a moment when I type it directly into the command line as none of these files are larger than 160KB and some are significantly smaller. This is what I type in and what I get when I try to run the file (HW is the correct directory)

localhost:HW Mirel$ MigrateNshell.sh
-bash: MigrateNshell.sh: command not found

我已经陷入这个僵局两天了,所以任何输入都将不胜感激!谢谢!!

I've been at this impass for two days now, so any input would be greatly appreciated! Thanks!!

推荐答案

出于安全原因,shell 不会在当前目录(默认情况下)搜索可执行文件.您必须具体,并告诉 bash 您的脚本在当前目录 (.) 中:

For security reasons, the shell will not search the current directory (by default) for an executable. You have to be specific, and tell bash that your script is in the current directory (.):

$ ./MigrateNshell.sh

这篇关于Shell 脚本未运行,未找到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆