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
Jake Paul knocked out Mike Perry in the 6th round 👊
I expected to win. I should have won in the first round, but Perry survived. Mike Tyson, you're next, sign the contract.
#Box
👁Subscribe to Main Event | Sport News
Jake Paul on the fight with Mike Perry:
"Maybe at the beginning, he’ll land a couple of heavy shots, maybe he’ll be all wild and unpredictable, but as the fight progresses, I’ll start breaking him down with my footwork, jab, and body shots."
#Box
👁Subscribe to Main Event | Sport News
Diaz Sues Organizers of Fight with Masvidal
#box#mma
Nate Diaz has filed a lawsuit against the organizers of the fight with Jorge Masvidal.
Nate claims he had an agreement for a $10,000,000 payout for the fight. He received an advance payment of $1,000,000, with the remaining $9,000,000 to be paid after the fight. The lawsuit states that the company is refusing to make the payments, claiming that the event was unprofitable.
👁Subscribe to Main Event | Sport News