厨师投诉

问题描述:

我想设置以下内容在我的.bash_profile厨师投诉

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

file '/home/me/.bash_profile' do 
    cotent bash_profile_conent 
end 

厨师抛出这个错误:

==> 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)}\[email protected]\h:\w [$ENV]\$ " 
==> Server-002: ... 

显然厨师认为@角色是为Unicode转义。

我想按原样使用@。我该如何解决这个错误?

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

irb > "\[email protected]" 
SyntaxError: (irb):1: invalid Unicode escape 
"\[email protected]" 
^

但:

irb > "\u0611" 
=> "ؑ" 

记住%Q(...)行为就像一个双引号字符串,以便所有常见的转义(如\u为Unicode)的申请。加入更多的反斜杠应该可以理清:

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