You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Joachim Ansorg edited this page Nov 12, 2021
·
4 revisions
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
#!/usr/bin/env bashif [ "$(echo"$1"| wc -c )"-gt 1 ];thenecho"greater than 1"fiif [ "$(echo"$1"| wc -m )"-gt 1 ];thenecho"greater than 1"fiif [ "${#1}"-gt 1 ];thenecho"greater than 1"fi