I just want to echo an incremented string length. For example:
STR="test"
echo ${#STR}
It prints 4, but I want to print 5.
I just want to echo an incremented string length. For example:
STR="test"
echo ${#STR}
It prints 4, but I want to print 5.
The length of the string cannot be changed without modifying the string. If you want to add another character at the beginning, try
STR="a$STR"
Now ${#STR}
is 5, because STR
is atest
(five characters).
If you want to perform arithmetic in the shell, use an arithmetic expression:
echo "$((1+${#STR}))"