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

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
主站蜘蛛池模板: 东安县| 克什克腾旗| 岳阳县| 长春市| 德昌县| 海盐县| 大庆市| 北流市| 新宁县| 若尔盖县| 墨脱县| 台北县| 深州市| 运城市| 南和县| 女性| 印江| 虎林市| 湾仔区| 军事| 长海县| 施秉县| 五华县| 新兴县| 平舆县| 永定县| 辽阳市| 竹北市| 京山县| 通渭县| 井冈山市| 武安市| 晴隆县| 福建省| 大兴区| 沅陵县| 泾川县| 林州市| 五家渠市| 平潭县| 博白县|