0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux][command] シェル変数と環境変数_echo, unset, export

Last updated at Posted at 2025-02-01

シェル変数

有効範囲:定義したシェル・プロセスのみ
環境変数への変更方法:exportコマンドを使用する

環境変数

有効範囲:定義したシェル・プロセス・子プロセス

unsetコマンド

$ unset 変数名
オプション 由来 説明
default unset - 指定したシェル変数や関数を削除(環境変数も含む)

exportコマンド

$ export 変数名

シェル変数から環境変数

BashA
$ EV=world
$ SV=local
$ export EV
$ bash ←新しいシェルを起動
BashB(子プロセス)
$ echo $EV
// 出力結果
// world ←引き継がれる(環境変数化)

$ echo $SV
// 出力結果
//    ←引き継がれない

環境変数PATHに値の追加

$ export PATH=$PATH:値(追加するディレクトリ名)

代表的な環境変数

環境変数 由来 説明
HOME home directory 現在のユーザーのホームディレクトリのパス
例: /home/user
USER user name 現在のログインユーザー名
PATH executable path 実行ファイルを検索するディレクトリのリスト
コロン : で区切る
PWD present working directory 現在の作業ディレクトリ(カレントディレクトリ)
LANG language システムのロケール(言語や文字コードの設定)
例: ja_JP.UTF-8
HOSTNAME host name マシンのホスト名
EDITOR editor デフォルトで起動するエディタ
LD_LIBRARY_PATH loader dynamic library path 共有ライブラリのパス
HISTFILE history file コマンド履歴を保存するファイルのパス ~/.bash_history
HISTSIZE history size (memory) 現在のシェル に保存されるコマンド履歴の最大保存数
シェル終了後に削除
HISTFILESIZE history file size ~/.bash_history に保存されるコマンド履歴の最大保存数
シェル終了後に維持

Ping-t

変数値設定

環境変数

unset

export

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?