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

  • 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
主站蜘蛛池模板: 新晃| 大邑县| 盖州市| 株洲市| 博野县| 和顺县| 营口市| SHOW| 赫章县| 习水县| 辽宁省| 巴林右旗| 汤阴县| 晋江市| 台湾省| 锡林浩特市| 辛集市| 叙永县| 武宣县| 宁蒗| 南通市| 满城县| 肇东市| 楚雄市| 贵定县| 聂拉木县| 临西县| 揭阳市| 河池市| 曲水县| 榆中县| 恩平市| 贵定县| 尚义县| 罗平县| 双牌县| 中超| 大连市| 临沂市| 蒙山县| 临潭县|