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

查看:585
本文介绍了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

这一系列的问题只是将每个基因座每个位点的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结尾.回声线是有关程序需要信息的计数(每个基因座的碱基对,分析中的种群,每个位点的样本等)的数据.猫形线将通过回声线中指定的特定于站点的信息下面的所有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.

要创建外壳脚本,我一直在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天全站免登陆