如何在“\”之后打印$ 2的内容

时间:2013-11-29 06:42:28

标签: bash shell

我有一个名为“test.sh”的脚本

#!/bin/bash
echo "sed -i '/$1/c\$2' $3"

./test.sh "This line is removed." "some text here" out.txt身份运行。我希望打印完全

sed -i '/This line is removed./c\some text here' out.txt

输出打印为:

sed -i '/This line is removed./c$2' out.txt

问题在于\$打印$不允许$2的内容。怎么做?

2 个答案:

答案 0 :(得分:2)

在脚本中使用双斜线:

#!/bin/bash
echo "sed -i '/$1/c\\$2' $3"

答案 1 :(得分:2)

试试这个

echo "sed -i '/$1/c\\$2' $3"