Variable
Variable
Variable substitution within quotes
# foo=bar
 echo "'$foo'"
#'bar'
# double/single quotes around single quotes make the inner single quotes expand variablesGet the length of variable
var="some string"
echo ${#var}
# 11Get 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
var="some string"
echo ${var:2}
#me stringReplacement (e.g. remove the first leading 0 )
var="0050"
echo ${var[@]#0}
#050Replacement (e.g. replace 'a' with ',')
{var/a/,}Replace all (e.g. replace all 'a' with ',')
{var//a/,}#with grep
 test="god the father"
 grep ${test// /\\\|} file.txt
 # turning the space into 'or' (\|) in grepTo change the case of the string stored in the variable to lowercase (Parameter Expansion)
var=HelloWorld
echo ${var,,}
helloworldExpand and then execute variable/argument
cmd="bar=foo"
eval "$cmd"
echo "$bar" # fooLast updated
Was this helpful?