这些 bash 完成建议有何相关性?

这些 bash 完成建议有何相关性?

~$HOME。对我来说,cd ~/home/cat。到目前为止很简单,是吗?

在 Bash 中,会发生以下情况:

cat @ mint-kitty : ~/Downloads $ cd ~ # from /home/cat/Downloads to /home/cat/, as an example, but behaviour happens with any directory
cat @ mint-kitty : ~ $ cd ~<TAB>proxy/ # oh? what's this?
cat @ mint-kitty : /bin $ cd ~<TAB><TAB>
~ais                ~clamav/            ~debian-tor/        ~gitlog             ~list               ~mixmaster/         ~ntp                ~redis/             ~stunnel4           ~systemd-resolve    ~uuidd/
~avahi/             ~cl-builder/        ~dirmngr/           ~gnats              ~lp                 ~monkeysphere/      ~oident/            ~roard/             ~sync/              ~systemd-timesync/  ~vde2-net
~avahi-autoipd/     ~clickpkg           ~dnsmasq/           ~irc                ~mail/              ~mpd/               ~pdnsd/             ~root/              ~syncache/          ~timidity/          ~whoopsie
~backup/            ~colord/            ~epmd               ~jetty/             ~man/               ~muroard/           ~postgres/          ~rtkit/             ~sys/               ~tomcat8            ~www-data/
~bin/               ~daemon/            ~festival           ~libvirt-dnsmasq/   ~mdm/               ~mysql              ~proxy/             ~saned              ~syslog             ~trafficserver      
~bind/              ~Debian-exim/       ~games/             ~libvirt-qemu/      ~memcache           ~news               ~pulse              ~speech-dispatcher  ~systemd-bus-proxy/ ~uml-net            
~cat/               ~debian-spamd/      ~gitdaemon          ~lightdm/           ~messagebus/        ~nobody             ~radvd              ~sshd/              ~systemd-network    ~uucp               
cat @ mint-kitty : /bin $ cd ~systemd-resolve 
bash: cd: /run/systemd/resolve: No such file or directory
1 | cat @ mint-kitty : /bin $ cd ~redis
cat @ mint-kitty : /var/lib/redis $ cd ~clamav
cat @ mint-kitty : /var/lib/clamav $ cd ~irc
bash: cd: /var/run/ircd: No such file or directory
1 | cat @ mint-kitty : /var/lib/clamav $ cd ~gnats
bash: cd: /var/lib/gnats: No such file or directory
1 | cat @ mint-kitty : /var/lib/clamav $ cd ~sshd
cat @ mint-kitty : /var/run/sshd $ cd ~nobody
bash: cd: /nonexistent: No such file or directory

显然,<TAB>代表 TAB 键以 ASCII 发送字节9,而不是实际的文本。

我在提示中留下了PS1显示当前路径和返回代码的信息。我的问题是,这些目录自动完成的相关性是什么~

我创建了一个表格,其中包含这些内容以及它们指向的位置,以便更好地理解它们(但我现在更困惑了)。

thing            points-at?
===========================================
~ais             ENOENT /home/ais/         # user ais uid=156(ais) gid=163(ais) groups=163(ais) does not have an entry in /home/
~avahi           /var/run/avahi-daemon/
~avahi-autoipd   /var/lib/avahi-autoipd/
~backup          /var/backups/
~bin             /bin/
~bind            /var/cache/bind/
~cat             /home/cat/
~clamav          /var/lib/clamav/
~cl-builder      /usr/share/common-lisp//  # two slashes
~clickpkg        ENOENT /nonexsistent/     # yes, really
~colord          /var/lib/colord/
~daemon          /usr/sbin/                # ??
~Debian-exim     /var/spool/exim4/         # ??
~debian-spamd    /var/lib/spamassassin/
~debian-tor      /var/lib/tor/
~dirmngr         /var/cache/dirmngr/
~dnsmasq         /var/lib/misc/             # ??
~epmd            /var/run/epmd/
~festival        ENOENT /home/festival      # user festival uid=131(festival) gid=29(audio) groups=29(audio) does not have an entry in /home/
~games           /usr/games/                # ???
~gitdaemon       ENOENT /nonexistent/
~gitlog          ENOENT /nonexistent/
~gnats           /var/lib/ircd/
~jetty           /usr/share/jetty8/
~libvirt-dnsmasq /var/lib/libvirt/
~libvirt-qemu    /var/lib/libvirt/
~lightdm         /var/lib/lightdm/
~list            ENOENT /var/list/
~lp              ENOENT /var/spool/lpd/
~mail            /var/mail/
~man             /var/cache/man/
~mdm             /var/lib/mdm/
~memcache        ENOENT /nonexistent/
~messagebus      /var/run/dbus
~mixmaster       /var/lib/mixmaster/
~monkeysphere    /var/lib/monkeysphere/
~mpd             /var/lib/mpd/
~muroard         /var/lib/muroard/
~mysql           ENOENT /nonexistent/
~nobody          ENOENT /nonexistent/
~ntp             ENOENT /home/ntp            # user ntp uid=107(ntp) gid=114(ntp) groups=114(ntp) does not have an entry in /home/
~oident          /                           # ????
~pdnsd           /var/cache/pdnsd/
~postgres        /var/lib/postgresql/
~proxy           /bin/
~pulse           ENOENT /var/run/pulse
~radvd           ENOENT /var/run/radvd
~redis           /var/lib/redis
~roard           /var/lib/roard
~root            /root
~rtkit           /proc
~saned           ENOENT /var/lib/saned
~speech-dispatcher ENOENT /var/run/speech-dispatcher
~sshd            /var/run/sshd
~stunnel4        ENOENT /var/run/stunnel4
~sync            /bin/
~syncache        /var/run/syncache-drb/
~sys             /dev/                       # ???
~syslog          ENOENT /home/syslog         # user syslog uid=104(syslog) gid=109(syslog) groups=109(syslog),4(adm) does not have an entry in /home/
~systemd-bus-proxy /run/systemd/
~systemd-network ENOENT /run/systemd/netif/
~systemd-resolve ENOENT /run/systemd/resolve/
~systemd-timesync /run/systemd/
~timidity        /etc/timidity/
~tomcat8         ENOENT /usr/share/tomcat8/
~trafficserver   ENOENT /var/run/trafficserver/
~uml-net         ENOENT /home/uml-net/       # user uml-net uid=146(uml-net) gid=155(uml-net) groups=155(uml-net) does not have an entry in /home/
~uucp            ENOENT /var/spool/uucp/
~uuidd           /run/uuidd/
~vde2-net        ENOENT /var/run/vde2/
~whoospie        ENOENT /nonexistent/
~www-data        /var/www

thing列是由 所示的条目~<TAB><TAB>points-at要么是目录thing指向,要么是不存在的位置thing指向。

例如,~cat给出bash: /home/cat: Is a directory,所以~cat -> /home/cat但是~clickpkg给出bash: /nonexistent: No such file or directory,所以~clickpkg -> ENOENT /nonexistent/

我已经提供了我所掌握的所有数据。这里发生了什么?难道是~被秘密扩大到了什么?

答案1

A~user$HOME该用户的目录。这是由所有这些增强的
目录列表(第二列):~

awk -F ":" '{printf( "%15s \t %-20s\n",$1,$6)}' /etc/passwd

来自 man bash (搜索“波浪号扩展”)

波形符扩展
如果波形符前缀中的任何字符均未加引号,则波形符前缀中跟在波形符后面的字符将被视为可能的登录名。
...波浪号前缀被替换为与指定登录名关联的主目录。

相关内容