mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2000 (markdown)
11
SC2000.md
11
SC2000.md
@@ -1,5 +1,10 @@
|
|||||||
# See if you can use ${#variable} instead
|
# 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
|
## example code
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
@@ -8,4 +13,8 @@
|
|||||||
if [ "$( echo "$1" | wc -c )" -gt 1 ]; then
|
if [ "$( echo "$1" | wc -c )" -gt 1 ]; then
|
||||||
echo "greater than 1"
|
echo "greater than 1"
|
||||||
fi
|
fi
|
||||||
```
|
|
||||||
|
if [ "$( echo "$1" | wc -m )" -gt 1 ]; then
|
||||||
|
echo "greater than 1"
|
||||||
|
fi
|
||||||
|
```
|
Reference in New Issue
Block a user