2015-10-07 124 views
2

我想設置以下內容在我的.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轉義。

我想按原樣使用@。我該如何解決這個錯誤?

回答

3

這不是真的問題,\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]\\$ " 
)