问题
I have a really simple function in bash script that tells me the current directory. However it gives the error bash: =/home/users/abc: No such file or directory
$currentdir is empty.
Why is this happening? I also tried
$currentdir=`pwd`
and that didn't work too.
This is a similar question Bash: current directory variable and I tried this but it didn't solve my problem.
xpwd() {
$currentdir=$(pwd)
echo "current dir is $currentdir"
}
回答1:
When you want to set a variable, you don't use the $
:
currentdir=`pwd`
The $
is for when you want to do a variable substitution.
回答2:
Assigning to a variable is without the '$' sign. Using the value is with the '$' sign.
currentdir=`pwd`
回答3:
try:
currentdir=`pwd`
(remove the $
)
来源:https://stackoverflow.com/questions/35189157/how-to-get-a-variable-to-have-the-current-dir-path