EN
Bash - get string length
3
points
In this article, we would like to show you how to get string variable length in Bash.
Quick solution:
length=${#string}
Practical example
In this example, we present how to use # operator to get string variable length. Then we use echo command to display the result in the console.
Example script.sh file:
#!/bin/bash
string="abc"
length=${#string}
echo "Length: $length"
Run in command line:
./script.sh
Output:
Length: 3