Bash:用perl动态替换
这个问题在这里已经有了答案:
  删除" + " (空格和加号)。  Bash自动连接相邻的字符串。 
echo 'hi!'t"here"  # hi!there
  以这种方式生成Perl代码是安全的,因为id -g -n $USER的输出不会包含 , $ , @或/ 。 
你要去
GROUPNAME="$(id -g -n $USER)"
perl -i -pe's/(PLACEHOLDER)/'"$GROUPNAME"'/g' filepath/file
但是没有理由生成Perl代码。 这是非常容易出错的。 请改用以下方法之一:
export GROUPNAME="$(id -g -n $USER)"
perl -i -pe's/(PLACEHOLDER)/$ENV{GROUPNAME}/g' filepath/file
要么
GROUPNAME="$(id -g -n $USER)" perl -i -pe's/(PLACEHOLDER)/$ENV{GROUPNAME}/g' filepath/file
                        链接地址: http://www.djcxy.com/p/29129.html
                        
                        
                    