我编写了一个bash脚本,它使用各种程序执行一系列生物信息学任务。我想知道如何传递这个脚本--一串文件名--在连续的情况下执行相同的分析。
假设我有这样的东西:
name=a.txt
echo "this is a test" >> $name
echo "this is also a test" >> $name
echo "this is still a test" >> $name我以为我能做到
for i in 'b.txt c.txt d.txt'
do
name=$i
echo "this is a loop test" >> $name
echo "this is also a loop test" >> $name
echo "this is still a loop test" >> $name
done来达到同样的目的。但很明显这不管用。我怎样才能做到这一点?
谢谢,
哑光
发布于 2014-09-24 16:23:51
如果我理解你想做什么,你的例子似乎大部分都是正确的。要从命令行参数获取文件列表,可以这样做:
#!/bin/sh
for file in "$@"; do
echo "text" >> $file
done发布于 2014-09-24 16:23:07
文件名周围的引号是问题所在,没有它们它就能工作。
https://stackoverflow.com/questions/26021773
复制相似问题