320x100
320x100
시스템 환경변수를 쉘 파일 내에서 사용하기
#!/bin/bash
eval $(egrep -v '^#' .env | xargs) COMMAND
echo ${설정한 환경변수}
.env 파일의 환경변수를 쉘 파일 내에서 사용하기
- 전역 변수로 설정
#!/bin/bash
# 리눅스 커널 버전마다 다르다
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
export $(grep -v '^#' .env | xargs -d '\n')
elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then
export $(grep -v '^#' .env | xargs -0)
fi
echo ${설정한 환경변수}
- 사용자 환경변수로 설정
set -a # automatically export all variables
source .env
set +a
환경변수 키만 뽑아내기
while read line; do
echo $line | cut -f 1 -d'='
done < .env
Reference
Set environment variables from file of key/value pairs
TL;DR: How do I export a set of key/value pairs from a text file into the shell environment? For the record, below is the original version of the question, with examples. I'm writing a script in b...
stackoverflow.com
How to set environment variables from .env file
Let's say I have .env file contains lines like below: USERNAME=ABC PASSWORD=PASS Unlike the normal ones have export prefix so I cannot source the file directly. What's the easiest way to create a
stackoverflow.com
300x250
728x90
'Computer Science > Linux' 카테고리의 다른 글
쉘 파일 if 문 (0) | 2023.08.25 |
---|---|
쉘 파일 args 인자값 처리하기 (0) | 2023.08.25 |
백엔드 개발자라면 알아야할 리눅스 필수 명령어 모음 (0) | 2023.07.07 |
우분투 기본 방화벽 ufw (0) | 2023.05.15 |
커맨드 라인 환경에서 REST API (HTTP) 요청 (0) | 2023.04.24 |