How to get a variable to have the current dir path? [duplicate]

我只是一个虾纸丫 提交于 2020-06-22 03:46:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!