Bash Tilde Expansion

帅比萌擦擦* 提交于 2019-12-12 09:53:31

问题


Is it possible to add to the rules that bash uses for tilde expansion? I'd like to have ~data expand to /data/users/me, ~scratch expand to /data/scratch/me etc.. Is this possible, or does bash have too tight a tight hold on the '~'?

Thanks,

Andrew


回答1:


Tilde expansion is tied to users' home directories (or the contents of the directory stack or $PWD or $OLDPWD). Use variable expansion, aliases or functions to accomplish what you're after. You can also use CDPATH to list a set of directories for cd to look in for destination directories.




回答2:


~user expands to the home directory of the specified user. A nasty hack that would work is to create user named data with home directory /data/users/me etc. Adding users is distribution-specific.



来源:https://stackoverflow.com/questions/4651856/bash-tilde-expansion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!