bash 获取环境变量
In Bash, ~username
gives the username
user’s home. However, this does not work for situations where username
is in a variable such as
在Bash中, ~username
给出username
用户的家。 但是,这不适用于username
位于变量(例如)中的情况
~$user
How to get the home directory from the user name in a variable in Bash?
如何从Bash中的变量中的用户名获取主目录?
You can use this Bash script snippet:
您可以使用以下Bash 脚本片段:
userhome=$(eval echo ~$user)
Here, $user
get evaluated to its value (say VALUE) and then ~VALUE
will be evaluated again by eval
which gives the same effect as ~username
.
在这里, $user
得到评估它的价值(VALUE说),然后~VALUE
将再次评估eval
这给同样的效果~username
。
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。
bash 获取环境变量