I just want to understand following line of code in shell. It is used to get the current working directory. I am aware that $(variable)
name return the value inside the variable name, but what is $(command)
supposed to return? Does it return the value after executing the command? In that case, we can use `
to execute the command.
CWD="$(cd "$(dirname $0)"; pwd)"
Same output can be taken from the following line of code also in different version of shell
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
I am unable to understand the meaning of $(cd..
and $(dirname
.
Could anybody help me to figure out how this command get executed?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…