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
🔥NEW RELEASE🔥
😁Half Guard by Nicholas Meregali😁
➡️Master the Half-Guard with 4 hours of step-by-step instruction designed to give you real control and understanding of this essential position. Learn to dominate in three key stages, Legs, Hips, and Shoulders, using each to solve specific problems and create clear, strategic progress.
➡️We start with the core concept of Camping, teaching you how to stabilize your position, manage pressure, and control posture through precise body placement over your opponent’s shields, hips, and frames, making your base extremely hard to off-balance.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#NewWave#Gi#HalfGuard
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Top Half Guard By Neil Melanson😁
➡️Unlock a powerful, high-pressure top game with Top Half Guard by legendary coach Neil Melanson. As a master of catch wrestling and MMA grappling, Neil’s unique approach to half guard will completely transform the way you dominate from top position.
➡️Whether you're new to half guard or looking to refine your existing skills, this series gives you the tools to overwhelm your opponent, control the position, and finish the fight with devastating submissions
➡️Learn from one of the most innovative grappling minds in the sport and elevate your game to new heights.
$127😍$11.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NeilMelanson#BJJFanatics#HalfGuard
💁♀️Buy
💁♀️
😁Precision Attacks and Sweeps From Butterfly Half and Knee Shield by Shawn Melanson😁
➡️Shawn Melanson returns with his fifth installment for BJJ Fanatics, and this time he’s pulling back the curtain on the sneaky, frustrating, and relentlessly effective guard system that’s been quietly dismantling opponents at every level.
➡️Melanson's method breaks away from flashy tricks and focuses on the real structure behind guard retention, off-balancing, and transitioning from defense to decisive offense
̶$̶7̶9̶😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#ShawnMelanson#HalfGuard#NoGi#Butterfly
💁♀️Buy
💁♀️