reload_flag=""
if [[ -n "${DEBUG}" ]]; then
reload_flag="--reload"
fi
if [[ -n "${WORKER_COUNT}" ]]; then
workers=${WORKER_COUNT}
else
workers=2
fi
gunicorn --workers ${workers} \
--bind 0.0.0.0:8000 \
${reload_flag} main.wsgi
Писали такие конструкции чтобы проверить наличие флага и сформировать команду правильно?
На самом деле можно сделать тоже самое проще. Для этого используются операторы условной подстановки, доступные в оболочках семейства POSIX.
:- для установки значений по умолчанию
${WORKER_COUNT:-2}
Если переменная не объявлена, то будет дефолтное значение 2.
:+ подставляет указанный текст, если переменная не пуста
${DEBUG:+--reload}
Если что-то есть в переменной то распечатается текст после символа +, в противном случае - ничего. Удобно для опциональных флагов, как в нашем примере.
Итого наш скрипт может выглядеть так:
gunicorn --workers ${WORKER_COUNT:-2} \
--bind 0.0.0.0:8000 \
${DEBUG:+--reload} main.wsgi
Есть еще два оператора.
:= не только подставить дефолтное значение, но и присвоить его переменной, если она пуста
# никаких переменных еще нет
VAL1=${VAL2:=hello}
# теперь доступны обе
echo $VAL1 $VAL2
# hello hello
:? остановить выполнение с ошибкой, если переменной нет.
echo ${MISS:?is required}
bash: MISS: is required
Код выхода будет 1.
#tricks#linux
Withering soul
Little by little she dies everyday
Demons everywhere she's losing her sight
Pain has reached her bones
Breathing freely is a luxury now
she resists but she knows she is a withering soul
she is screaming but can anyone hear her?
The world's gone deaf
All eyes are shut, no one sees what's right in front of them
She is not the only one
She won't be the last one
Time is a flat circle, Nietzsche said
Once upon a time humans came into this world, cursed to repeat their doings time and time and time again
Fading souls don't await the eternal rest
There is no rest, there is no end to their agony
Trapped they are, born prisoners
Freedom was never a dream only an illusion
#review
#modern#poetry
🌈SOLD❤️ for $10,000,000. (CAN) - Located in West Vancouver Canada.
#Luxury#Modern#Mansion
📷Listed By malcolmhasman
💁Via @TheLuxuryClub
✔️🔜@R_Group_Official
━━━━━━━━━━━━━━━━━