zshシェルでPATH = ~ / .local / bin:$ PATHをどこに設定する必要がありますか?

zshシェルでPATH = ~ / .local / bin:$ PATHをどこに設定する必要がありますか?

現在の環境(Fedora35、zshユーザーシェル、oh-my-zsh、pyenv)では ~/.local/binパスには存在しません。

問題は、それを追加する「正しい」場所がどこにあるかということです。

さまざまなオプションがあります。

  • ~/.zshrc
  • ~/.zログイン
  • ~/.zshenv
  • ~/.zprofile

またはシステム全体:

  • /etc/zshenv

は、「ksh」シミュレーションモードで/etc/zprofile標準を取得するために使用されます/etc/profile/etc/profile.d/*sh

# from /etc/zprofile

       #  Make /etc/profile happier, and have possible ~/.zshenv options like                      
       # NOMATCH ignored.                                                                          
       #                                                                                           
       emulate -L ksh                                                                              
                                                                                                   
       # source profile                                                                            
       if [ -f /etc/profile ]; then                                                                
           source /etc/profile                                                                     
       fi    

(望むより:https://apple.stackexchange.com/questions/388622/zsh-zprofile-zshrc-zlogin-what-goes-where)

他の可能性もあります(pam_env)。


Fedoraには/etc/profileチェックラインブロックが含まれています。インタラクティブシェル(オプションを含むi${-}

                                                                                                   
   for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do                                       
       if [ -r "$i" ]; then                                                                        
           if [ "${-#*i}" != "$-" ]; then                                                          
               . "$i"                                                                              
           else                                                                                    
               . "$i" >/dev/null                                                                   
           fi                                                                                      
       fi                                                                                          
   done                                                                                            


その行のテストでは、式はif [ "${-#*i}" != "$-" ]; thenループ${-#*i}変数とは何の関係もありませんが、「()で終わる開始文字列をオプションリストから削除」$iを意味し、次のように解釈されます。i#*i${-}

# with (interactive) zsh

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do echo "<${-#*i}> <$->"; done
<kmsy> <569NRXZghikmsy>
<kmsy> <569NRXZghikmsy>
<kmsy> <569NRXZghikmsy>

# with (interactive) bash

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do echo "<${-#*i}> <$->"; done
<mBHs> <himBHs>
<mBHs> <himBHs>
<mBHs> <himBHs>
<mBHs> <himBHs>



から:https://tldp.org/LDP/abs/html/internalvariables.html

$-

スクリプトに渡されたフラグ(setを使用)これは、もともとBashで使用されたksh構成でした。そのための1つの可能な用途は、インタラクティブであるかどうかをスクリプト自体テストすることです。

複数包含を防止する/etc/profile.d/*sh方法であってもよいインタラクティブシェル。

/etc/bashrcこのケースはInteractiveによって処理されますbash

                                                                                                  
# Source global bash config, 
# when interactive but not posix or sh mode                          
   if test "$BASH" &&\                                                                             
      test -z "$POSIXLY_CORRECT" &&\                                                               
      test "${0#-}" != sh &&\                                                                      
      test -r /etc/bashrc                                                                          
   then                                                                                            
      # Bash login shells run only /etc/profile                                                    
      # Bash non-login shells run only /etc/bashrc                                                 
      # Check for double sourcing is done in /etc/bashrc.                                          
      . /etc/bashrc                                                                                
   fi
         

ベストアンサー1

おすすめ記事