VSCode, Vagrant and Shell Scripts: $’\r’: command not found

By | March 7, 2018

I was playing about with a small Vagrant lab on my Windows 10 computer and using vscode as my code editor when I ran into an issue when trying to run a bash script on my Linux system. (I’ll cover a quick start guide to Vagrant for local test and dev environments soon)

It was just a small bash script to run an nginx Docker container. But every time I ran the script I either got  : No such file or directory or something like line 2: $’\r’: command not found.

It turns out that this is because the sh file was save in the DOS format, where windows can insert special characters to denote a return on a line, such as ‘\r’.

A couple of ways to fix the issue is to change the file EOL sequence on vscode from “CRLF” to “LF” at the bottom of the console.

Or you could use dos2unix to convert the EOL sequence from the Linux command line:

$ sudo yum install dos2unix

$ sudo dos2unix /vagrant/provision_scripts/webSetup.sh

Leave a Reply

Your email address will not be published. Required fields are marked *