Chef complaints about invalid Unicode escape

Anthony Kong

I want to set the following content in my .bash_profile

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 throws this error:

==> 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: ...   

Apparently chef thinks the @ character is meant for unicode escape.

I want to use @ as is. How can I fix this error?

mu is too short

The isn't really the problem, the \u is. For example:

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

but:

irb > "\u0611"
 => "ؑ" 

Keep in mind that %Q(...) behaves like a double quoted string so all the usual escapes (such as \u for Unicode) apply. Adding more backslashes should sort things out:

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]\\$ "
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unicode escape syntax in Java

From Dev

Maven complaints about Joda-Time even though I installed it

From Dev

Unicode escape error

From Dev

JSON Unicode escape sequence - lowercase or not?

From Dev

Automatically escape unicode characters

From Dev

Ruby trying to dynamically create unicode string throws "invalid Unicode escape" error

From Dev

Clear invalid escape in python?

From Dev

Escape unicode escaping in Java

From Dev

Double colon in class name and RubyMine complaints about short name

From Dev

How to escape UNICODE string in python (to javascript escape)

From Dev

Unicode escape behavior in Java programs

From Dev

Invalid hex escape

From Dev

Converting twitter archive unicode escape

From Dev

encode unicode characters to unicode escape sequences

From Dev

Is a unicode escape valid in the let keyword

From Dev

Decode unicode escape characters with perl

From Dev

How to solve SonarQube complaints about my code?

From Dev

Convert Text to Unicode Escape Sequence

From Dev

Javascript: Invalid Unicode escape sequence while storing accessing unicode

From Dev

Dart flutter FormatException: Invalid unicode escape

From Dev

How to solve SonarQube complaints about my code?

From Dev

JSON Unicode escape sequence - lowercase or not?

From Dev

Java Invalid escape sequences

From Dev

Is this Python unicode escape error?

From Dev

Escape unicode escaping in Java

From Dev

Chef - ArgumentError: too short control escape

From Dev

Invalid hex escape

From Dev

Decode unicode escape characters with perl

From Dev

Invalid escape in identifier php