diff --git a/SC2001.md b/SC2001.md index e73b791..8942b07 100644 --- a/SC2001.md +++ b/SC2001.md @@ -14,7 +14,7 @@ string="stirng" ; echo "${string//ir/ri}" ### Rationale: -Let's assume somewhere earlier in your code you have put data into a variable (Ex: $string). Now you want to do a search and replace inside the contents of $string and echo the contents out. You could pass this to sed as done in the example above, but for simple substitutions utilizing the shell for the same feature is a lot simpler and should be utilized whenever possible. +Let's assume somewhere earlier in your code you have put data into a variable (Ex: $string). Now you want to do a search and replace inside the contents of $string and echo the contents out. You could pass this to sed as done in the example above, but for simple substitutions, parameter expansion can do it with less overhead. ### Exceptions @@ -25,3 +25,9 @@ string="stirng" ; echo "$string" | sed -e "s/^.*\(.\)$/\1/" ``` This is a bit simple for the example and there are alternative ways of doing this in the shell, but this SC2001 flags on several of my crazy complex sed commands which are beyond the scope of this example. Utilizing some of the more complex capabilities of sed is required occasionally and it is safe to ignore SC2001. + +### Related resources: + +* Bash Manual: [Shell Parameter Expansion](https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion) +* Wooledge BashGuide: [Parameter Expansion](https://mywiki.wooledge.org/BashGuide/Parameters#Parameter_Expansion). +* Bash Hacker Wiki: [Parameter Expansion](http://wiki.bash-hackers.org/syntax/pe) \ No newline at end of file