From d2968d66519a79f7836fb2f1b20a38dee09c917c Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 9 Sep 2017 16:27:44 -0700 Subject: [PATCH] Created SC1017 (markdown) --- SC1017.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 SC1017.md diff --git a/SC1017.md b/SC1017.md new file mode 100644 index 0000000..832c72c --- /dev/null +++ b/SC1017.md @@ -0,0 +1,32 @@ +## Literal carriage return. Run script through `tr -d '\r'` . + +### Problematic code: + +```sh +$ cat -v myscript +#!/bin/sh^M +echo "Hello World"^M +``` + +### Correct code: + +```sh +$ cat -v myscript +#!/bin/sh +echo "Hello World" +``` +### Rationale: + +The script uses Windows/DOS style `\r\n` line terminators instead of UNIX style `\n` terminators. The additional `\r` aka `^M` aka carriage return characters will be treated literally, and results in all sorts strange bugs and messages. + +You can verify this with `cat -v yourfile` and see whether or not each line ends with a `^M`. To delete them, open the file in your editor and save the file as "Unix", "UNIX/OSX Format", `:set ff=unix` or similar if it supports it. + +If you don't know how to get your editor to save a file with Unix line terminators, you can use `tr`: + + tr -d '\r' < badscript > goodscript + +This will read a script `badscript` with possible carriage returns, and write `goodscript` without them. + +### Exceptions: + +None \ No newline at end of file