博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bash 获取环境变量_如何从Bash中的变量中的用户名获取用户的主目录?
阅读量:2518 次
发布时间:2019-05-11

本文共 636 字,大约阅读时间需要 2 分钟。

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 in a variable in Bash?

如何从Bash中的变量中的获取主目录?

You can use this Bash 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 获取环境变量

转载地址:http://pqlwd.baihongyu.com/

你可能感兴趣的文章
正则表达式的搜索和替换
查看>>
个人项目:WC
查看>>
地鼠的困境SSL1333 最大匹配
查看>>
flume+elasticsearch+kibana遇到的坑
查看>>
【MM系列】在SAP里查看数据的方法
查看>>
C#——winform
查看>>
CSS3 transform制作的漂亮的滚动式导航
查看>>
《小强升职记——时间管理故事书》读书笔记
查看>>
Alpha 冲刺(3/10)
查看>>
Kaldi中的Chain模型
查看>>
spring中的ResourceBundleMessageSource使用和测试示例
查看>>
css规范 - bem
查看>>
电梯调度程序的UI设计
查看>>
转自 zera php中extends和implements的区别
查看>>
Array.of使用实例
查看>>
【Luogu】P2498拯救小云公主(spfa)
查看>>
如何获取网站icon
查看>>
几种排序写法
查看>>
java 多线程的应用场景
查看>>
dell support
查看>>