Ask Your Question

How to make erb templates strip out carriage return characters

asked 2015-04-19 13:27:00 -0600

Gray Fox gravatar image

I'm working on Windows (using VMs) and I added some .sh scripts to provision, but they are all written with carriage return characters, which apparently really confuse bash, so when I try to run them I get strange errors like

syntax error near unexpected token `$'{\r''

Can I somehow tell puppet/ruby to strip out carriage returns when writing .sh files or .sh.erb files to the machine? I can configure my git and IDE to never use carriage return characters, but I would like to save my team the hassle of having to do the same.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-20 15:18:42 -0600

Gray Fox gravatar image

I ended up crating a .gitattributes file with the following lines:

# Don't put carriage return inside .sh files because it corrupts them.
*.sh -crlf
*.sh.erb -crlf

Should be self-explanatory; it disables git's core.autocrlf config that's enabled on Windows by default.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-04-19 13:27:00 -0600

Seen: 764 times

Last updated: Apr 20 '15