On mac running 4.4.23(1), an example I've seen used for finding the length of a string throws an error:
string_var=blah
echo `expr length $string_var`
expr: syntax error
Works fine on my Debian system.
shopt options are: himvBHs
On mac running 4.4.23(1), an example I've seen used for finding the length of a string throws an error:
string_var=blah
echo `expr length $string_var`
expr: syntax error
Works fine on my Debian system.
shopt options are: himvBHs
expr
is not part of bash -- it's an ancient UNIX tool from back when the shell couldn't do math (or much else useful) on its own.
You don't need it. In the modern day, ${#var}
will give you the length of the value assigned to var
, as follows:
string_var=blah
echo "${#string_var}"