From cb15fa420d73783cf575fc49891cc587095bcb23 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 29 Mar 2014 10:28:20 -0700 Subject: [PATCH] Created SC2123 (markdown) --- SC2123.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 SC2123.md diff --git a/SC2123.md b/SC2123.md new file mode 100644 index 0000000..572848b --- /dev/null +++ b/SC2123.md @@ -0,0 +1,30 @@ +## PATH is the shell search path. Use another name. + +### Problematic code: + + PATH=/my/dir + cat "$PATH/myfile" + +### Correct code: + +Good practice: always use lowercase for unexported variables. + + path=/my/dir + cat "$path/myfile" + +Bad practice: use another uppercase name. + + MYPATH=/my/dir + cat "$MYPATH/myfile" + +### Rationale: + +`PATH` is where the shell looks for the commands it executes. By inadvertently overwriting it, the shell will be unable to find commands (like `cat` in this case). + +You get this warning when ShellCheck suspects that you didn't meant to overwrite it (because it contains a non-`/bin` path but no path separators (`:`)). + +Best shell scripting practice is to always use lowercase variable names to avoid accidentally overwriting exported and internal variables. + +### Contraindications + +If you're aware of the above and really do want to set your shell search path to `/my/dir`, you can ignore this warning. \ No newline at end of file