About the problem of variable $foo in "" quotes in Linux
Now we get an incoming parameter from the command line $1
, assuming the value of $1 is 666
We want to use $1 in sed -i, assuming the command is sed -i " s/foo/$1/g” file.txt
Now we need to write an ant build.xml (can be understood as a script), and we need to implement the sed instruction:
<exec executable="/usr/bin/sed" dir="common/self_cleaning_builder">
<arg line="#我需要的那条sed指令"/>
</exec>
我应该如何把这个sed指令放入arg标签下的line=“”中,才能使得我放进去的指令可以被正确读出且实现功能?引号太多了,怎么写都实现不了功能。
What I wrote is:
<exec executable="/usr/bin/sed" dir="/common">
<arg line='-i -r "s/foo//g" file.txt'/>
</exec>
as well as
<property name="regex" value="s/input//g"/>
<exec executable="/usr/bin/sed" dir="/common">
<arg line="-i -r $regex file.txt"/>
</exec>
But none of them can achieve the function I want.
After reading some posts about “” and ‘”, I still don’t know how to solve this problem. I hope you can give me some advice
Just write a
wrapper
forsed
. If you usesed
directly like this, you will first get the parameters andthink it is a file,
$1
will not work$1 is an input parameter in the shell script, but not in the ant script. In addition, when you call ant from the command line, it is impossible to pass parameters by position. You must specify the parameter name:
Use ${arg1} to access variables in ant script: