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
🐹Solution for the mini-game
in Hamster Kombaton September21!
💎Receive a diamond for completing the task!
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:Daily Combo for August30th!
🔸 Cointelegraph
🔸 Risk management team
🔸 Setting up business processes
Combine these cards to win 5,000,000 coins! 💰
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:New Card Alert!
📝Your Human Talent
💡 Is your most important talent.
📊Profit per hour: +1.5K
💰Cost: 35,000 coins
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:New Card Alert!
🔍 No Expensive Mistakes
If you don’t manufacture a quality product, all you’ve got at the end is a bunch of expensive mistakes.
💰 Profit per hour: +800
💸 Cost: 17,000 coins
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat :New Card Alert for August 28th!
🗣️ Speak Clearly, If You Speak at All
“The way to get started is to quit talking and begin doing.”
Profit per hour: +400
Cost: 10,000 coins
🔔🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Solution for the mini-game with a key inHamster Kombaton August 27th! 🔑
➕A new mini-game has been added!
Now, connect hexagon tiles of the same color to earn coins.
⭐️Play as many times as you want!
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat :New Card Alert for August27th!
🌾 Feed a Growing Population & Enhance Food Security
In the next 30 years, we will need to produce as much food as was produced in the last 10,000 years.
Profit per hour: +4K
Cost: 60,000 coins
🔔🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Solution for the newmini-game
in Hamster Kombaton August 26th!
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:New Card Added!
🌕MoonPay is now available!
A whole world of crypto in one simple account. Buy, sell, and swap seamlessly. Say hello to the new way to crypto!
💰Earn 20K per hour with this card.
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap