Variable

Variable

Variable substitution within quotes

# foo=bar
 echo "'$foo'"
#'bar'
# double/single quotes around single quotes make the inner single quotes expand variables

Get the length of variable

var="some string"
echo ${#var}
# 11

Get the first character of the variable

var=string
echo "${var:0:1}"
#s

# or
echo ${var%%"${var#?}"}

Remove the first or last string from variable

Replacement (e.g. remove the first leading 0 )

Replacement (e.g. replace 'a' with ',')

Replace all (e.g. replace all 'a' with ',')

To change the case of the string stored in the variable to lowercase (Parameter Expansion)

Expand and then execute variable/argument

Last updated

Was this helpful?