- 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
推薦閱讀
- 基于C語言的程序設計
- 21小時學通AutoCAD
- Windows 7寶典
- Storm應用實踐:實時事務處理之策略
- Windows Server 2008 R2活動目錄內幕
- 基于企業網站的顧客感知服務質量評價理論模型與實證研究
- 統計挖掘與機器學習:大數據預測建模和分析技術(原書第3版)
- 精通LabVIEW程序設計
- Hands-On Dashboard Development with QlikView
- 傳感器與自動檢測
- Web編程基礎
- 工業機器人操作
- Wireshark Revealed:Essential Skills for IT Professionals
- 案例解說虛擬儀器典型控制應用
- SQL Server 2017 Machine Learning Services with R