fast →💬 You could create an env var MY_NAME withexport MY_NAME="Wade Wilson" 💬 Then you could use it with other programs, likeecho "Hello $MY_NAME" Hello Wade Wilson
여기서는 "World"를 넣었기에 기본값으로써 사용됩니다. 넣지 않으면 None 이 기본값으로 사용됩니다.
그러면 해당 파이썬 프로그램을 다음과 같이 호출할 수 있습니다:
fast →💬 Here we don't set the env var yetpython main.py 💬 As we didn't set the env var, we get the default value Hello World from Python
💬 But if we create an environment variable firstexport MY_NAME="Wade Wilson" 💬 And then call the program againpython main.py 💬 Now it can read the environment variable Hello Wade Wilson from Python
fast →💬 Here we don't set the env var yetpython main.py 💬 As we didn't set the env var, we get the default value Hello World from Python
💬 But if we create an environment variable first$Env:MY_NAME = "Wade Wilson" 💬 And then call the program againpython main.py 💬 Now it can read the environment variable Hello Wade Wilson from Python
환경변수는 코드 바깥에서 설정될 수 있지만, 코드에서 읽을 수 있고, 나머지 파일과 함께 저장(git에 커밋)할 필요가 없으므로, 구성이나 설정 에 사용하는 것이 일반적입니다.
특정 프로그램 호출에 대해서만 사용할 수 있는 환경 변수를 만들 수도 있습니다. 해당 프로그램에서만 사용할 수 있고, 해당 프로그램이 실행되는 동안만 사용할 수 있습니다.
그렇게 하려면 프로그램 바로 앞, 같은 줄에 환경 변수를 만들어야 합니다:
fast →💬 Create an env var MY_NAME in line for this program callMY_NAME="Wade Wilson" python main.py 💬 Now it can read the environment variable Hello Wade Wilson from Python
💬 The env var no longer exists afterwardspython main.py Hello World from Python