如何获得一个具有当前目录路径的变量? [英] How to get a variable to have the current dir path?
本文介绍了如何获得一个具有当前目录路径的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在bash脚本中有一个非常简单的功能,可以告诉我当前目录.但是,它给出错误bash: =/home/users/abc: No such file or directory
$ currentdir为空.
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`
那也行不通.
这是一个类似的问题, Bash:当前目录变量,我尝试了此操作,但并没有不能解决我的问题.
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"
}
推荐答案
要设置变量时,请勿使用$
:
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.
这篇关于如何获得一个具有当前目录路径的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文