Introduction
You use ${#var} to find out how many characters are in a string. This helps when you want to check or use the length of text in your script.
length=${#variable}name="hello" len=${#name} echo $len
empty="" len=${#empty} echo $len
text="hello world" len=${#text} echo $len
#!/bin/bash input="Bash scripting" length=${#input} echo "The length of '$input' is $length."
${#var} do in a bash script?${#var}var.name in bash?${#variable}, so for name it is ${#name}.text="Hello World"
echo ${#text}echo ${#text} prints the length, which is 11.myvar=Hello length=$#myvar echo $length
$# returns the number of positional parameters passed to the script, not the length of a string variable.length=$#myvar tries to get positional parameters count, ignoring myvar. So it does not get string length.input is empty or not in a bash script. Which condition correctly uses string length to do this?${#input}.[ ${#input} -eq 0 ] correctly tests if the string length is zero.Pass the test and this pattern moves unknown