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?

More than 5 years have passed since last update.

bashでシェル変数を環境変数に変換する

Posted at

なにがしたい?

別ファイルで定義されているシェル変数を環境変数に変換したい。
初歩的だけど思いつくのに数分かかったのでメモ

方法

環境変数はexportで定義できるので、純粋にexportしてあげればいい。

var.sh
var="qiita"
run.sh
# !/usr/bin/env bash

source ./var.sh
export var=$var #ここが大事
./print.sh
print.sh
# !/usr/bin/env bash

echo $var

export var=$varしないと、print.shにvarの値が引き継がれない

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?