월별 글 목록: 2021년 10월월

Bash 경로 완성은 sudo와 어떻게 작동합니까? 탭 경로 완성이

탭 경로 완성이 작동하지 않습니다 (적어도 우분투 및 AFAIK 아치에서는)

sudo mount <whatever>

마운트하려는 iso 파일이에 없습니다 /etc/fstab. 방금 입력하면

mount <whatever>

완료가 작동합니다 (물론 명령은 루트가 아니므로 실패합니다). 분명히 그것은 그것을 sudo깨뜨립니다.

sudo로 완성 작업을 어떻게 할 수 있습니까?

와 함께 놀라운

sudo umount <whatever>

완성 작품. 어떻게 달성됩니까? 그것은 조사합니까 /etc/fstab?

해결책 : 인수에 전달 된 쉘 스크립트를 /usr/local/bin호출에 넣었 sudo mount ...습니다. sudo방해 가 없기 때문에이 스크립트를 호출 할 때 완료가 작동합니다 .



답변

이것은 전혀 관련이 bash없지만 패키지에 프로그래밍 된 완료에 따라 다릅니다 bash-completion.

파일의 일부 주석에서 /etc/bash_completion.d/mount:

# mount(8) completion. This will pull a list of possible mounts out of
# /etc/{,v}fstab, unless the word being completed contains a ':', which
# would indicate the specification of an NFS server. In that case, we
# query the server for a list of all available exports and complete on
# that instead.
#

# umount(8) completion. This relies on the mount point being the third
# space-delimited field in the output of mount(8)
#

또한 주 파일 /etc/bash_completion에서 명시 적으로 설명 mount하고 umount명령 하는 다음 주석 을 찾을 수 있습니다 .

# A meta-command completion function for commands like sudo(8), which need to
# first complete on a command, then complete according to that command's own
# completion definition - currently not quite foolproof (e.g. mount and umount
# don't work properly), but still quite useful.
#

업데이트 :
에 대한 의견 mountumount에서 명령을 제거 bash_completion
(가)에서 커밋 :

_command_offset: Restore compopts used by called command.

This fixes completions that rely on their compopts, most notably
mount(8).
Fixes bash-completion bug #313183.

출시bash-completion 1.90


답변

Arch Wiki를 살펴보면 쉽게 해결할 수 있습니다 .

과 같은 명령을 입력 한 후 자동 완성 기능 (키보드에서 Tab 키를 두 번 누름)을 사용하는 것이 유용합니다 sudo.

이렇게하려면이 형식의 줄을 ~/.bashrc파일에 추가하십시오.

완료 -cf your_command

예를 들어 sudoman다음에 자동 완성 기능을 사용하려면 다음을 수행하십시오 .

complete -cf sudo
complete -cf man

답변

아니요, fstab에서 보이지 않습니다. Bash complete는 경로의 명령, bashrc 및 / 또는 bash_profile의 별칭 및 경로를 찾습니다. 당신이 같은 sudo mount /mnt/some_folder것을 입력 하면 자동 완성해야합니다. 어쩌면 당신이 당신을했을 때 당신은 umount목적지의 상대 경로에 있었고 자동 완성을했습니다.


답변

bash는 너무 복잡하고 이식성이 떨어지기를 원하지 않기 때문에 / dev에서 마운트 작업 완료를 제안하지 않습니다.

그러나 umount를 호출하면 df / mount / etc의 출력을 쉽게보고 마운트 된 장치와 위치를 알 수 있습니다.

아마도 zsh는 마운트 완료를 제공하고, scp 명령을 수행 할 때 자동 완성 zck도 제공합니다 …


답변