
Bash에서 디렉토리 이름 앞에 입력하지 않고 요소의 하위 디렉토리로 이동하여 autocd
합계를 결합하는 방법이 있습니까 ?CDPATH
CDPATH
cd
예를 들어, 다음 디렉토리가 있는 경우:
- ~
- ~/류트
- ~/로트/힌즈
- ~/로트/쿤즈
- ~/딩거
- ~/딩지/집
- ~/딩거/자동
그리고 할
~$ shopt -s autocd
~$ export CDPATH=":~/Leute:~/Dinge"
그럼 난 할 수 있어
~$ Leute
~/Leute 디렉토리로 이동합니다(그게 다입니다 autocd
).
~/Leute$
난 할 수 있어
~/Leute$ cd Auto
마지막으로 ~/Dinge/Auto(그거 CDPATH
) 를 입력하세요.
~/Dinge/Auto$
하지만 둘을 합치면 효과가 없을 것 같습니다. 예를 들어 ~/Leute에서 시작하면 명시적인 지침 없이는 ~/Dinge/Auto로 이동할 수 없습니다 cd
.
~/Leute$ Auto
bash: Auto: Command not found...
이유가 있나요? 아니면 이 작업을 수행하는 데 필요한 다른 것이 있습니까?
답변1
의도적으로든 실수로든 디렉터리 이름을 입력했는지 여부에 대한 테스트에서는 다음 변수를 검색하지 않는 것 같습니다 CDPATH
.
execute.cmd.c
, 기능 execute_simple_command
:
if (autocd && interactive && words->word && is_dirname (words->word->word))
{
words = make_word_list (make_word ("cd"), words);
xtrace_print_word_list (words, 0);
goto run_builtin;
}
is_dirname
동일한 소스 파일에 정의되어 있습니다 .
/* Return 1 if the file found by searching $PATH for PATHNAME, defaulting
to PATHNAME, is a directory. Used by the autocd code below. */
static int
is_dirname (pathname)
char *pathname;
{
char *temp;
int ret;
temp = search_for_command (pathname, 0);
ret = (temp ? file_isdir (temp) : file_isdir (pathname));
free (temp);
return ret;
}
autocd
여기에서 디렉토리를 찾을 수 있는 것처럼 보이지만 PATH
(for )로 테스트한 결과 오류가 발생했습니다.X11
/usr/bin/X11/
X11: No such file or directory