IFS는 Internal Field Separator의 약자로 외부프로그램을 실행할 때 입력되는 문자열을 나눌 때 기준이 되는 문자를 정의하는 변수이다. bash의 내부 필드 구분자(internal field separator)가 공백/탭/줄바꿈이다. 구분자는 IFS 변수에 설정되어 있다.
PROGRAMMING="
java programming
python programming
c programming
"
echo "-------------------------"
for p in $PROGRAMMING; do
echo $p
done
# IFS를 줄바꿈(newline)로 변경
echo "-------------------------"
OLD_IFS="$IFS"
IFS=$'\n'
for p in $PROGRAMMING; do
echo $p
done
IFS="$OLD_IFS"
$ bash test.sh
-------------------------
java
programming
python
programming
c
programming
-------------------------
java programming
python programming
c programming
CLUSTER_ID="5FFZMTA6C"
BATCH_START_DATE="20210228"
BATCH_END_DATE="20210420"
while true; do
if [ $BATCH_START_DATE -gt $BATCH_END_DATE ]; then
exit 0
fi
day_of_week=$(date -d "${BATCH_START_DATE}" "+%A")
if [ $day_of_week == "Sunday" ] || [ $day_of_week == "Tuesday" ]; then
DISP_START_DATE=$(date -d "${BATCH_START_DATE} +1days" "+%Y%m%d")
DISP_END_DATE=$(date -d "${BATCH_START_DATE} +7days" "+%Y%m%d")
echo "BATCH: $BATCH_START_DATE"
echo "./backfill.sh $_CLUSTER_ID stat $DISP_START_DATE $DISP_END_DATE;"
fi
sleep 0.1
BATCH_START_DATE=$(date -d "${BATCH_START_DATE} +1days" "+%Y%m%d")
done
$ bash test7.sh | grep backfill
./backfill.sh stat 20210301 20210307;
./backfill.sh stat 20210303 20210309;
./backfill.sh stat 20210308 20210314;
./backfill.sh stat 20210310 20210316;
./backfill.sh stat 20210315 20210321;
./backfill.sh stat 20210317 20210323;
./backfill.sh stat 20210322 20210328;
./backfill.sh stat 20210324 20210330;
./backfill.sh stat 20210329 20210404;
./backfill.sh stat 20210331 20210406;
./backfill.sh stat 20210405 20210411;
./backfill.sh stat 20210407 20210413;
./backfill.sh stat 20210412 20210418;
./backfill.sh stat 20210414 20210420;
./backfill.sh stat 20210419 20210425;
./backfill.sh stat 20210421 20210427;
# output
$ bash test.sh
+ NUM=100
+ echo 100
100
++ date
+ TIME='2021년 4월 10일 토요일 03시 19분 28초 KST'
2021년 4월 10일 토요일 03시 19분 28초 KST
test.sh: line 9: UNDIFIED: unbound variable