bashでautocdとCDPATHを一緒に使用しますか?

bashでautocdとCDPATHを一緒に使用しますか?

Bashでディレクトリ名の前に入力せずに要素のサブディレクトリに移動してautocd合計を結合する方法はありますか?CDPATHCDPATHcd

たとえば、次のディレクトリがある場合:

  • ~
  • ~/リュート
  • ~/ロット/ヒンズ
  • ~/ロット/クーンズ
  • ~/ディンガー
  • ~/ディンジ/ハウス
  • ~/ディンガー/自動

そして

~$ shopt -s autocd
~$ export CDPATH=":~/Leute:~/Dinge"

だから私はできます

~$ Leute

〜/ Leuteディレクトリに移動します(それはすべてですautocd)。

~/Leute$

私はできます

~/Leute$ cd Auto

最後に〜/ Dinge / Auto(それCDPATH)を入力してください。

~/Dinge/Auto$

しかし、2つを合わせると効果がないようです。たとえば、〜/ 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

おすすめ記事