環境変数を定義する他の方法はありますか?

環境変数を定義する他の方法はありますか?

私はLinuxに初めて触れました。 Debian Wheezyは私のラップトップ(64ビット)で動作しています。

ORACLE_SID最近、評価目的でOracle 11g R2データベースをインストールし、スクリプトを使用して環境変数を定義しました(例:/etc/profile.d/oracle.shこれはうまく機能しますが、「oracle」ユーザーの場合)。

ユーザーを変更しますsu - oracle。 D
値がORACLE_SIファイルで指定された値と異なります/etc/profile.d/oracle.sh。 oracleユーザーのホームディレクトリにはファイル(例:.bash_profileetc.)がないので.profile、この値はどこから来ましたか?

環境変数のオーバーロード順序は何ですか?

ベストアンサー1

何を設定しても、最終的に環境変数が勝ちます。したがって、問題ではありません。$HOME/.bashrcOracleユーザー・ファイルの変数を下に設定しました。

このファイル$HOME/.bashrcはキーファイルで、対応するソースファイルは以下のファイル/etc/bashrcです/etc/profile.d/*.sh。それで、ただORACLE_SID=whatever設定してみました$HOME/.bashrc

デバッグのヒント

何が起こっているかを確認するには、次のようにログインをデバッグできます。

su - oracle -c "env SHELLOPTS=xtrace bash"

上記のコマンドを使用すると、bashからさまざまなファイルを取得できるため、次の手順を実行できます。

...
...
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/less.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/less.sh
+++ '[' -x /usr/bin/lesspipe.sh ']'
+++ export 'LESSOPEN=||/usr/bin/lesspipe.sh %s'
+++ LESSOPEN='||/usr/bin/lesspipe.sh %s'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/PackageKit.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/PackageKit.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/qt.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/qt.sh
+++ '[' -z /usr/lib64/qt-3.3 ']'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/udisks-bash-completion.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/udisks-bash-completion.sh
+++ '[' -z '4.1.7(1)-release' ']'
+++ complete -o filenames -F __udisks udisks
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/vim.sh ']'
++ '[' '[\u@\h \W]\$ ' ']'
++ . /etc/profile.d/vim.sh
+++ '[' -n '4.1.7(1)-release' -o -n '' -o -n '' ']'
+++ '[' -x //usr/bin/id ']'
++++ //usr/bin/id -u
+++ '[' 0 -le 200 ']'
+++ return
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/which2.sh ']'
...
...

おすすめ記事