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
😄Draw
➖➖➖➖➖➖
🔘 Drawis commonly used as a verb that means creating a picture or image
🔜My cousin drew our family using different coloured pencils.
🔜My daughter has just learned to draw!
🔘We can also use the verb ‘draw’ to mean attracting attention - someone wanting to look at something.
🔜The amazing singer drew a huge audience.
🔜A World Cup game is guaranteed to draw a large number of viewers!
🔘 Drawas a noun can also describe competition results that are equal.
🔜The football match ended in a draw – it was 1:1.
🔜This boxer has never lost a fight - he has six wins and a draw.
#Draw👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys
⚠️ The project was suspended. Funds may be at risk.
🌟Starverse — Telegram Stars Farming and Everyday Giveaways
Earning stars has never been so exciting! #Starverse is a game where your tickets turn into real money. A project from the TgLab team, creators of the popular TON Dating mini app.
⏳Farming
Every hour you can turn on farming and take a part of the total income of the players.
Half of all revenue goes to farmers — the more tickets you have, the bigger the drop.
Farm, reinvest and invite friends — you'll get 15% of their purchases.
💰Golden Ticket
Every day at 9:00 UTC a winner is randomly selected and receives 15% of all purchases made during the day.
How to participate:
- farm at least 3 hours a day
- buy at least one ticket on the day of the drawing
💰Easy Withdraw
Got Stars? You can immediately transfer them to your Telegram account or convert to $USDT without delays.
⭐️Start farming now!
#stars#farming#draw#web3