bash 参数中的主目录扩展 (~)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1685894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
home directory expansion (~) within an argument
提问by Yoo
When I enter the following (BASH):
当我输入以下内容(BASH)时:
rdesktop -r disk:bacon=~/bacon host
It does not expand to
它不会扩展到
rdesktop -r disk:bacon=/home/me/bacon host
It seems the "disk:" part is the problem as can be seen in:
似乎“磁盘:”部分是问题所在,如下所示:
$ echo bacon=~/bacon disk:bacon=~/bacon
bacon=/home/me/bacon disk:bacon=~/bacon
How can I make tilde expand?
我怎样才能让波浪号展开?
回答by P Shved
While ~ does not expand (it's used as specially routed of the path), $HOMEdoes.
虽然 ~ 不会扩展(它用作路径的特殊路由),$HOME但会扩展。
rdesktop -r disk:bacon=$HOME/bacon host
But be careful with environment-changing su!
但要小心环境变化su!
回答by pilcrow
rdesktop -r disk:bacon=$(echo ~/bacon) host
rdesktop -r disk:bacon=$(echo ~/bacon) host
will do it. It won't please the eye, but it will work.
会做的。它不会让眼睛高兴,但它会起作用。

