@ysongzybl
2015-05-08T19:20:03.000000Z
字数 927
阅读 1620
bash
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?
#!/bin/bash
version=$1
echo $version
sed 's/\${version.number}/$version/' template.txt > readme.txt
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.
sed "10q;d" file.txt
argument q: quit searching
argument d: delete pattern space, start next cycle
To store the output to a variable, use
line=$(sed "10q;d" file.txt)
echo $line
http://stackoverflow.com/questions/3204302/how-to-use-a-bash-script-variable-with-sed
http://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file
http://stackoverflow.com/questions/6749128/store-output-from-sed-into-a-variable