我有以下一行:
env JAVA_OPTS="-Djava.library.path=/the_path/:/the_path/:/the_path/:/the_path:"$LIBRARY_PATH" -Xms2g -Xmx4g -XX:MaxPermSize=256M -Dsun.net.client.defaultConnectTimeout=60000 -Dsun.net.client.defaultReadTimeout=60000 -Dspring.profiles.active=release"
我想在最后一个引号之前添加新变量(类似于new_fancy_variable = yes)。所以这一行应该是这样的:
env JAVA_OPTS="-Djava.library.path=/the_path/:/the_path/:/the_path/:/the_path:"$LIBRARY_PATH" -Xms2g -Xmx4g -XX:MaxPermSize=256M -Dsun.net.client.defaultConnectTimeout=60000 -Dsun.net.client.defaultReadTimeout=60000 -Dspring.profiles.active=release new_fancy_variable=yes"
问题是我该怎么做?目前我有一个命令:
sed 's/^env JAVA_OPTS=\".*$/& new_fancy_variable=yes\"/' myfile.conf
...但我不知道如何删除新变量之前的最后一个问号。
答案 0 :(得分:1)
sed '/^env JAVA_OPTS=/s/"$/ new_var=yes"/' ...
答案 1 :(得分:0)
您不需要env
。您可以将值固定到具有myvar+="additopnal=value".
Your original
的var。将JAVA_OPTS`构造为
JAVA_OPTS="-Djava.library.path=/the_path/:/the_path/:/the_path/:/the_path:$LIBRARY_PATH"
# Add mem setings
JAVA_OPTS+=" Xms2g -Xmx4g -XX:MaxPermSize=256M"
# add Timeouts
JAVA_OPTS+=" -Dsun.net.client.defaultConnectTimeout=60000 -Dsun.net.client.defaultReadTimeout=60000"
# Add profile
JAVA_OPTS+=" -Dspring.profiles.active=release"
不要忘记在单词之间添加空格。 现在添加一些花哨的东西很简单:
JAVA_OPTS+=" new_fancy_variable=yes"
如果要将其添加到文件中,可以尝试
echo '# Fancy support
JAVA_OPTS+=" new_fancy_variable=yes"' >> myfile.conf
你只需要检查在最后一行添加它是否正确(没有流量控制或配置中的部分)