- 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
推薦閱讀
- ABB工業機器人編程全集
- Visualforce Development Cookbook(Second Edition)
- Div+CSS 3.0網頁布局案例精粹
- 會聲會影X5視頻剪輯高手速成
- Deep Learning Quick Reference
- 輕松學Java
- Hands-On Machine Learning with TensorFlow.js
- 模型制作
- STM32G4入門與電機控制實戰:基于X-CUBE-MCSDK的無刷直流電機與永磁同步電機控制實現
- Maya極速引擎:材質篇
- Photoshop CS3圖層、通道、蒙版深度剖析寶典
- 新手學電腦快速入門
- Google SketchUp for Game Design:Beginner's Guide
- Visual FoxPro數據庫基礎及應用
- 單片機C語言應用100例