From dcdf85d787e1310329a37bdc9a63286fd70a3bac Mon Sep 17 00:00:00 2001 From: John Gardner Date: Wed, 22 Dec 2021 18:56:34 +1100 Subject: [PATCH] Fix caps, highlighting, and spelling of brand names. --- SC1017.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/SC1017.md b/SC1017.md index 9b5d2eb..fd8bd60 100644 --- a/SC1017.md +++ b/SC1017.md @@ -2,7 +2,7 @@ ### Problematic code: -```sh +```console $ cat -v myscript #!/bin/sh^M echo "Hello World"^M @@ -10,20 +10,23 @@ echo "Hello World"^M ### Correct code: -```sh +```console $ 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. +The script uses Windows/MS-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. +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/macOS 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 +```sh +tr -d '\r' < badscript > goodscript +``` This will read a script `badscript` with possible carriage returns, and write `goodscript` without them. @@ -33,6 +36,5 @@ None ### Related resources: -* [BashFaq: How do I convert a file from DOS format to UNIX format (remove CRs from CR-LF line terminators)?](https://mywiki.wooledge.org/BashFAQ/052) -* [StackOverflow: Are shell scripts sensitive to encoding and line endings? -](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) \ No newline at end of file +* [BashFaq: How do I convert a file from MS-DOS format to Unix format (remove CRs from CR-LF line terminators)?](https://mywiki.wooledge.org/BashFAQ/052) +* [StackOverflow: Are shell-scripts sensitive to encoding and line-endings?](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings)