Bash 故障排除:不是有效标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11096412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash troubleshooting: Not a valid identifier
提问by user964689
Beginner here trying to get a pipeline working in bash. If somebody can see why when I run the following I get:
这里的初学者试图让管道在 bash 中工作。如果有人能明白为什么当我运行以下命令时,我会得到:
-bash: `$i': not a valid identifier,
that would be really helpful. Also if there are other mistakes please let me know
那真的很有帮助。另外如果有其他错误请告诉我
for $i in /home/regionstextfile; do tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt; done
The idea is for each line in regionstextfile (which contains genome coordinates) run a program called tabixin the vcf.bzfile, then with the output run vcftoolswith the specified options, then put all the outputs into the genomesregions.txtfile.
这个想法是为regionstextfile(包含基因组坐标)中的每一行运行一个tabix在vcf.bz文件中调用的程序,然后使用vcftools指定的选项运行输出,然后将所有输出放入genomesregions.txt文件中。
回答by Igor Chubin
That must be so:
一定是这样:
for i in `</home/regionstextfile`
do
tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done
When you use a variable (e.g. assign value to it or export it, or do anything but with the variable itself) you write its name without $; when you use a value of a variable you write $.
当你使用一个变量时(例如给它赋值或导出它,或者除了变量本身做任何事情)你写它的名字时没有$; 当你使用一个你写的变量的值时$。
EDIT:
编辑:
When region names contains spaces but each region is in a separate line, you need while:
当区域名称包含空格但每个区域都在单独的行中时,您需要while:
cat /home/regionstextfile | while read i
do
tabix /sequences/human_variation/snps/genotypes.vcf.gz "$i" | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done
回答by Nahuel Fouilleul
The same thing without cat :
没有 cat 也一样:
while read i
do
tabix /sequences/human_variation/snps/genotypes.vcf.gz "$i" | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done < /home/regionstextfile
Remark <file.txtcould not work unless IFS=''
<file.txt除非 IFS='',否则备注无法工作
OLDIFS="$IFS"
IFS=''
for i in `</home/regionstextfile`
do
tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done
IFS="$OLDIFS"

