일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 영화 후기
- 탐조
- Cannon PowerShot G7 X Mark III
- 갓생
- Rstuido
- 계묘년
- 영화 리뷰
- 영화 해석
- 더 웨일
- 토양미생물학
- 생명과학 균학 미생물학 Biology Mycology Microbiology
- 외생균근균
- 코딩
- R
- 곤줄박이
- RStudio
- 둠칫새
- 영화
- 대학원생
- 파이썬
- mushroom #mushrooms #mushroomhunting #mushroomphotos #mushroomphotography #mycology #mycologist #fungi #fungalecology #fungaldiversity #fantasticfungi #버섯 #탐균 #버섯탐사
- 토양학
- 에리히 프롬
- 젖비단그물버섯
- 철학
- 바운새
- 심리학
- 영화 일기
- 생물정보학
- 청도요
Archives
- Today
- Total
워라밸 중독자
[Shell script] 파이프라인 작성시 쉘 스크립트에서 안전하게 config 변수 불러오기 본문
현재 shell script에서 여러 하위 프로그램을 불러와서 사용할때
하위 프로그램의 변수를 고치고 싶다면
현재 shell script에서 config.yaml을 아래와 같이 전역 변수로 불러온다.
# Set the path to the config.yaml file as a global variable
export CONFIG_GLOBAL="절대경로/config.yaml"
# Load parameters from config file
echo "Loading parameters from config.yaml"
eval $(yq -r 'to_entries | .[] | .key + "=\"" + (.value | tostring) + "\""' ${CONFIG_GLOBAL} | sed -E 's/\(([^)]+)\)/$\1/g')
그리고 아래의 하위 프로그램에서 필요한 변수만 가져다 쓴다
# Load organism variable from config.yaml
organism=$(grep '^organism:' "$CONFIG_GLOBAL" | awk '{print $2}')
# Refine MSA based on organism type
if [[ "$organism" == "fungi" ]]; then
mafft --globalpair --adjustdirection --maxiterate 3 --thread 2 "${ALN}" > shrunk.aln.bt
else
mafft --adjustdirection --maxiterate 3 --thread 2 "${ALN}" > shrunk.aln.bt
fi
만약 config.yaml에 있는 모든 변수를 전역변수로 불러오게되면, 하위프로그램에서 사용하는 변수랑 꼬일 위험이 높다.
따라서 config만 전역변수로 불러오는 것이 안전하다.