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