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

  • 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
主站蜘蛛池模板: 阿拉善盟| 樟树市| 永登县| 岚皋县| 炎陵县| 灵川县| 云林县| 星子县| 北海市| 琼海市| 青海省| 云霄县| 马龙县| 达孜县| 东光县| 五峰| 阿图什市| 阜新市| 台北县| 滁州市| 财经| 呈贡县| 电白县| 娄烦县| 应用必备| 儋州市| 黑龙江省| 平果县| 静乐县| 茶陵县| 汉中市| 阜城县| 阿荣旗| 瑞安市| 普格县| 五寨县| 民县| 沙洋县| 哈巴河县| 疏附县| 定陶县|