What does ":" (colon) operator in a bash variable expansion: VAR=${TEMP:3}?
What is the meaning of the following line in a variable in bash?
VAR=${TEMP:3} 6 3 Answers
This is variable expansion and works like this (notice this is only bash and ksh specific and will not work in a POSIX shell):
$ x=1234567890
$ echo ${x:3}
4567890
$ echo ${x:7}
890
$ echo ${x:3:5}
45678${var:pos}means that the variablevaris expanded, starting from offsetpos.${var:pos:len}means that the variablevaris expanded, starting from offsetposwith lengthlen.
in bash it cuts away the first 3 characters of a (string) variable:
$ VAR="hello world"
$ echo ${VAR:3}
lo worldhave a look at 'substring extraction' here: .
This operator cuts off the first 3 characters of variable TEMP and assigns the rest to variable VAR.