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 3 years have passed since last update.

macで環境変数を設定&呼び出す方法

Last updated at Posted at 2020-08-16

slackbotなどを作るときに、TOKENを直接プログラム内に記述すると、情報漏れて危ない為、osの環境変数に設定することが推奨されています。

意外と、設定方法だけ書いてある記事が少なかったので、メモ。


export API_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxx (取得したTOKENを指定)

これで環境変数が設定完了

環境変数を呼び出すときは、


$API_TOKEN

pythonから環境変数を呼び出すときは、


import os
os.environ["API_TOKEN"]

注意点

上記の環境変数ですが、基本的にサーバーをログアウトすると消えてしまいますので一時対応となります。

もしサーバーにアプリをリリースして、運用したいといった場合は、~/.bash_profileと~/.bashrcに環境変数の設定を保存しておく必要があります。

対応手順詳細はこちらの記事が参考になります。

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?