- 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
推薦閱讀
- Java編程全能詞典
- 樂高機器人:WeDo編程與搭建指南
- Mastering Spark for Data Science
- 西門子PLC與InTouch綜合應用
- Visual C# 2008開發技術實例詳解
- 最簡數據挖掘
- 21天學通ASP.NET
- B2B2C網上商城開發指南
- Photoshop CS3圖層、通道、蒙版深度剖析寶典
- 網絡綜合布線設計與施工技術
- SAP Business Intelligence Quick Start Guide
- Excel 2007常見技法與行業應用實例精講
- 機器人人工智能
- Effective Business Intelligence with QuickSight
- 天才與算法:人腦與AI的數學思維