From 957afc9dd280d6ec72e99184e503082f0a55c2f4 Mon Sep 17 00:00:00 2001 From: jammer3d Date: Thu, 5 Jan 2017 15:19:28 -0500 Subject: [PATCH] Not confident with the rationale but the page was blank --- SC2010.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 SC2010.md diff --git a/SC2010.md b/SC2010.md new file mode 100644 index 0000000..e301349 --- /dev/null +++ b/SC2010.md @@ -0,0 +1,20 @@ +## Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames. + +### Problematic code: + +```sh +ls /directory | grep target_file_pattern +``` + +### Correct code: + +```sh +ls /directory/target_file_pattern +``` +### Rationale: + +Matching non-alphanumeric characters with grep may require escaping. Typically it is cleaner to use the built in pattern matching or another command like `find` + +### Exceptions: + +None \ No newline at end of file