I have written this to find the length of the string, but it doesn't show the length of the string.
Is there something wrong with what I have written? I'm just a beginner in bash.
Str=abcdefghj
echo "Str is:" `expr length $Str` "characters long"
I have written this to find the length of the string, but it doesn't show the length of the string.
Is there something wrong with what I have written? I'm just a beginner in bash.
Str=abcdefghj
echo "Str is:" `expr length $Str` "characters long"
This can be done natively in bash, no need to resort to expr
echo ${#Str}
Here is couple of ways to calculate length of variable :
echo ${#Str}
echo -n $Str | wc -m
echo -n $Str | wc -c
printf $Str | wc -m
expr length $Str
expr $Str : '.*'
Reference: http://techopsbook.blogspot.in/2017/09/how-to-find-length-of-string-variable.html
Try something like this:
echo "Str is: `expr length $Str` characters long"