2013-08-22 107 views
0

我期待创造一个bash脚本打印出一些额外的变量的文本文件,请参见下面打印文件出在bash

我想有这样的一个文本文件,它

bot1 
bot2 
bot3 

,然后有一个bash脚本把它打印出来,像这样

--exclude-agent="bot1" --exclude-agent="bot2" --exclude-agent="bot3" 

这可能吗?所以,如果我添加另一行到第一个文件,它将只打印另一个--exclude-agent =“我在文件中放入的任何文件”

目前我已经得到了下面的结果,但没有相当我想要的

#!/bin/bash 
while read line 
do 
echo "--exclude-agent="$line" \\" 
done < bots.txt 

任何帮助将是伟大的!

+0

http://mywiki.wooledge.org/XyProblem –

回答

0

这取决于你的意思是

不完全是我想要

首先,你有引用问题。正确的方法是

echo "--exclude-agent=$line \\" 

如果你想打印在同一行上尝试

echo -n "--exclude-agent=$line" 

如果你想保持在一个变量试试这个代码

params='' 
while read -r line 
do 
    params+="--exclude-agent=$line " 
done < bots.txt 
printf '%s\n' "$params" 

而且似乎就像你试图将参数存储在一个变量中一样。 Which is the worst idea ever

0

echo -n "--exclude-agent="$line"-n不打印最后\n从而使所有选项都在同一行

0

打印出预期的输出:

echo "--exclude-agent="\"$line"\" "