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
TON — LIVE: Telegram Rises in Popularity Rankings
#Telegram#apps
The channel TON — LIVE reports that Telegram has moved up one rank in the list of the most popular apps for 2025.
Source: link
@tonlines
⚡️Trending Apps: New Voting System in Telegram Apps Center
#Telegram#Apps
Trending Apps announces that users can now influence the ranking of Mini Apps through a new voting system in the Telegram Apps Center. Active participants will be rewarded with exclusive SBTs and Telegram Gifts.
Source: link
@tonlines
⚡️Trending Apps: Upcoming Feature in Apps Center
#Telegram#Apps
Trending Apps announced a new feature in the Apps Center, aiming to enhance user engagement by allowing users to influence developments directly. This innovative approach is set to launch within the next 30 days, with more details to be revealed gradually.
Source: link
@tonlines
A partir de hoy amigos, estaré entregando #apps, recursos, plataformas y tips para usar la tecnología a su favor y mejorar las condiciones de #empleo📄📈