Skip to content
The Bash Insectarium

/static/insetario/en/inseto/param-fatia/

Menu

BSH-014 · Parameters

${var:2:5}

A slice of the value: it starts at the offset, measures the length.

The slice counts from zero: ${var:4:3} skips four characters and takes three. Without the length, it runs to the end.

A negative offset counts from the end — but demands a space, ${var: -5}, so it does not turn into a :- default. On arrays, the same syntax slices elements instead of characters.

$ codigo="BSH-014-fatia"
$ echo ${codigo:4:3}
014
$ echo ${codigo: -5}
fatia
Three characters from the middle, five from the end.