Ubuntu – What does “:” (colon) operator in a bash variable expansion: VAR=${TEMP:3} bash What is the meaning of the following line in a variable in bash? VAR=${TEMP:3} Best Answer 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 variable var is expanded, starting from offset pos. ${var:pos:len} means that the variable var is expanded, starting from offset pos with length len. Related SolutionsUbuntu – How to increment a variable in bash There is more than one way to increment a variable in bash, but what you tried is not correct. You can use for example arithmetic expansion: var=$((var+1)) ((var=var+1)) ((var+=1)) ((var++)) Or you can use let: let "var=var+1" let "var+=1" let "var++" See also: http://tldp.org/LDP/abs/html/dblparens.html. Ubuntu – the meaning of $$1 in bash $$ is the PID (process id) of the current process. $$1 is the above PID followed by the literal string 1. So it is telling you that your bash is the process with PID 1930. But... free trick: show() { eval echo \$$1; } show PATH /home/romano/bin:/usr/local/bin:/bin:/usr/bin (quite convoluted, ain't it?) More info in TLDP. Related QuestionUbuntu – How to increment a variable in bashUbuntu – the meaning of $$1 in bashUbuntu – The point of the bash Null-operator “:”, colonUbuntu – What does a hash after a variable name do as an operator in bashUbuntu – variable expansion in single quoteUbuntu – What does the export PATH line in .bashrc doUbuntu – Bash variable expansion behavior when using single or double spaces
Best Answer
This is variable expansion and works like this (notice this is only
bash
andksh
specific and will not work in a POSIX shell):${var:pos}
means that the variablevar
is expanded, starting from offsetpos
.${var:pos:len}
means that the variablevar
is expanded, starting from offsetpos
with lengthlen
.