substring expansion
The ${name:offset:length} form, which takes part of a string starting at a zero-based offset.
In more detail
Leave out the length to run to the end of the string. A negative offset counts from the end but needs a space after the colon so it is not mistaken for the :- default form. The same form slices arrays.
Example
name=abcdef; echo "${name:1:3}"Related terms
- parameter expansion — Replacing a dollar sign and a variable name with the variable's value, optionally transformed by an operator inside curly braces.
- shell array — A variable that holds a numbered list of separate values, written in bash as names=(one "two words" three).
Taught in
- Pipelines, tee And Process Substitution — Bash Scripting & Command Line Automation
- Reshaping Text: cut, sort, uniq, tr, sed, awk — Bash Scripting & Command Line Automation
- Parameter Expansion: Defaults, Length, Slices — Bash Scripting & Command Line Automation