Ruby 厨师抱怨无效的Unicode逃逸

Ruby 厨师抱怨无效的Unicode逃逸,ruby,string,chef-infra,Ruby,String,Chef Infra,我想在我的.bash_配置文件中设置以下内容 bash_profile_content = %Q( export EDITOR=vi export ENV=#{role} export PATH=$PATH:/usr/local/bin export PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w [$ENV]\$ " ) file '/home/me/.bash_profile' do cotent bash_profile_conen

我想在我的.bash_配置文件中设置以下内容

bash_profile_content = %Q(
export EDITOR=vi
export ENV=#{role}
export PATH=$PATH:/usr/local/bin
export PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w [$ENV]\$ "
)

file '/home/me/.bash_profile' do
    cotent bash_profile_conent
end
Chef抛出此错误:

==> Server-002: [2015-10-07T03:02:23+00:00] ERROR: Exception handlers complete
==> Server-002: Chef Client failed. 0 resources updated in 322.419863736 seconds
==> Server-002: [2015-10-07T03:02:23+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> Server-002: [2015-10-07T03:02:23+00:00] ERROR: /var/chef/cache/cookbooks/servers/recipes/_common_user.rb:67: invalid Unicode escape
==> Server-002: ...ian_chroot:+($debian_chroot)}\u@\h:\w [$ENV]\$ "
==> Server-002: ...   
显然,chef认为
@
字符是用于unicode转义的


我想按原样使用
@
。如何修复此错误?

问题不是真正的问题,而是
\u
的问题。例如:

irb > "\u@"
SyntaxError: (irb):1: invalid Unicode escape
"\u@"
   ^
但是:

请记住,
%Q(…)
的行为类似于双引号字符串,因此所有常见的转义(例如Unicode的
\u
)都适用。添加更多反斜杠可以解决问题:

bash_profile_content = %Q(
export EDITOR=vi
export ENV=#{role}
export PATH=$PATH:/usr/local/bin
export PS1="${debian_chroot:+($debian_chroot)}\\u@\\h:\\w [$ENV]\\$ "
)
bash_profile_content = %Q(
export EDITOR=vi
export ENV=#{role}
export PATH=$PATH:/usr/local/bin
export PS1="${debian_chroot:+($debian_chroot)}\\u@\\h:\\w [$ENV]\\$ "
)