From e932d0853c2740264dda5a330698311d2711bd0d Mon Sep 17 00:00:00 2001 From: Christopher Slycord Date: Wed, 6 May 2020 19:18:14 +0900 Subject: [PATCH] Updated SC2000 (markdown) --- SC2000.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SC2000.md b/SC2000.md index b596904..7eb9833 100644 --- a/SC2000.md +++ b/SC2000.md @@ -1,5 +1,10 @@ # See if you can use ${#variable} instead +`${#variable}` will be equal to the number of characters in `"${variable}"` + +This is the same result as `"$( echo "$variable" | wc -m )"` +When "$variable" only contains single-byte characters, it's also the same as `"$( echo "$variable" | wc -c )"` + ## example code ``` bash @@ -8,4 +13,8 @@ if [ "$( echo "$1" | wc -c )" -gt 1 ]; then echo "greater than 1" fi -``` + +if [ "$( echo "$1" | wc -m )" -gt 1 ]; then + echo "greater than 1" +fi +``` \ No newline at end of file