如何使用bash脚本变量与SED [英] How to use a bash script variable with sed
本文介绍了如何使用bash脚本变量与SED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我执行以下bash脚本:
#!/斌/庆典
版本= $ 1
回声$版本
SED的/ \\ $ {version.number} / $版本/'template.txt> readme.txt文件
我期待与变量版本的内容来替代$ {} version.number所有实例。取而代之的是文字文本$版本被插入。
什么我需要做的,使SED使用$版本的当前值呢?
解决方案
sed的S / \\ $ {version.number} / $版/template.txt> readme.txt文件
只有双引号做的美元符号替代。这也意味着单引号不需要美元符号进行转义。
I execute the following bash script:
#!/bin/bash
version=$1
echo $version
sed 's/\${version.number}/$version/' template.txt > readme.txt
I'm expecting to replace all instances of ${version.number} with the contents of the variable "version". Instead the literal text $version is being inserted.
What do I need to do to make sed use the current value of $version instead?
解决方案
sed "s/\${version.number}/$version/" template.txt > readme.txt
Only double quotes do dollar-sign replacement. That also means single quotes don't require the dollar sign to be escaped.
这篇关于如何使用bash脚本变量与SED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文