HOWTO · Bash
コマンド ラインから .bash_profile をリロードする
このチュートリアルでは、bash プロファイルの操作について説明します。
このページの内容
シェルでは、.bash_profile を使用してユーザー設定の構成をカスタマイズします。 これはルートまたはホーム ディレクトリに保存され、他のユーザーにはほとんど隠されています。
このファイルは、シェルのすべての構成を保持し、構成スクリプトとも見なされます。 変数の仕様、エクスポート変数などが含まれます。
この記事では、macOS で .bash_profile を作成、削除、編集する方法について説明します。 必要なコマンドを使用して、それらを段階的に学習します。
.bash_profile を作成する
このパートでは、.bash_profile の作成方法を学びます。 この目的のために、以下のコマンドを使用します。
touch .bash_profile
.bash_profile の作成が完了したら、以下のコマンドを使用してファイルを確認できます。
ls -la
このコマンドを実行すると、次のような出力が得られます。
total 16
drwxr-xr-x 1 author author 4096 Aug 7 11:42 .
drwxr-xr-x 1 root root 4096 Nov 1 2021 ..
-rw------- 1 author author 5378 Aug 6 01:46 .bash_history
-rw-r--r-- 1 author author 220 Nov 1 2021 .bash_logout
-rw-r--r-- 1 author author 0 Aug 7 11:42 .bash_profile
-rw-r--r-- 1 author author 3771 Nov 1 2021 .bashrc
drwx------ 1 author author 4096 Dec 18 2021 .cache
drwx------ 1 author author 4096 Dec 18 2021 .config
drwx------ 1 author author 4096 Dec 18 2021 .dbus
drwxr-xr-x 1 author author 4096 Nov 1 2021 .landscape
-rw-r--r-- 1 author author 0 Aug 7 11:41 .motd_shown
-rw-r--r-- 1 author author 807 Nov 1 2021 .profile
-rw-r--r-- 1 author author 0 Nov 29 2021 .sudo_as_admin_successful
-rw-r--r-- 1 author author 0 Jul 6 15:26 disk_usage.txt
ここに、あなたの .bash_profile がリストされているのを見ることができます。
.bash_profile を編集してリロードする
.bash_profile が正常に作成されました。 ここで、いくつかの変更を行います。
.bash_profile を変更するには、nono エディターを使用できます。 以下のコマンドに従って、nono エディターで .bash_profile を開くことができます。
nano .bash_profile
.bash_profile ファイルの変更が完了したら、ファイルをリロードしてカスタマイズを有効にする必要があります。 これを行うには、以下の 2つのコマンドのいずれかを使用できます。
source .bash_profile
または、
source ~/.bash_profile
これで、.bash_profile の作成と変更が完了しました。 コマンドで実行しました。 任意のテキスト エディターを使用して手動で行うことができます。
この記事で使用するコードはすべて Bash で記述されていることに注意してください。 Linux シェル環境でのみ実行可能です。