如何获取变量以具有当前目录路径? [英] 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`
$
用于进行变量替换.
这篇关于如何获取变量以具有当前目录路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文