官术网_书友最值得收藏!

  • Bash Quick Start Guide
  • Tom Ryder
  • 164字
  • 2021-07-23 16:58:59

Tilde paths

A path that starts with a tilde character (~) is interpreted specially by the shell, for tilde expansion into a system user's home directory. By itself, it refers to the current user's home directory:

$ echo ~
/home/bashuser
$ echo ~/important
/home/bashuser/important

In this circumstance, it checks the value of the HOME environment variable first if it can. However, if this variable is blank or if the tilde is followed by any valid system username, Bash will attempt to find the home directory for that user with reference to the system password file, usually /etc/passwd:

$ echo ~root
/root
$ echo ~root/.ssh
/root/.ssh

If the user does not exist, Bash will leave the tilde string the same, without raising an error:

$ echo ~notauser
~notauser

If you want to print a tilde for a real user without expanding it, you need to quote it. Escaping, single-quoting, and double-quoting all work:

$ echo ~bashuser
/home/bashuser
$ echo \~bashuser '~bashuser' "~bashuser"
~bashuser ~bashuser ~bashuser
主站蜘蛛池模板: 读书| 济阳县| 通许县| 昂仁县| 台南市| 陈巴尔虎旗| 星子县| 盘锦市| 上栗县| 琼中| 电白县| 且末县| 平江县| 尉氏县| 河西区| 库尔勒市| 师宗县| 上杭县| 蒙山县| 德格县| 万州区| 萨迦县| 邵阳市| 仲巴县| 龙泉市| 孙吴县| 余干县| 恩平市| 灵璧县| 汝州市| 巴林右旗| 弥渡县| 满城县| 玛曲县| 屯门区| 鹤峰县| 镇沅| 宣恩县| 田林县| 苏州市| 纳雍县|