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
💨 Nothing on the road will scare you after this
🇸🇪 In Sweden, driving schools teach students how to handle a car in all kinds of tricky conditions.
🚗 And yes — passing a skid-control test is mandatory before they can even get their license.
#driving@Car_News
🚗🇺🇸1 IN 3 US PARENTS FEAR TEEN DRIVERS WILL CAUSE DEADLY CRASH
🔹 University of Michigan poll: 33% worry their young driver could cause accident — but 96% think their kid drives "average or better" 🤔📊
🔹 Half (51%) witnessed unsafe behavior: 44% saw aggressive driving, 25% caught texting while driving, 17% saw impaired/sleepy driving 😱🚨
🔹 Only 24% imposed consequences — most just take keys (6%), refuse car (8%), or threaten insurance cuts (6%) 🔑💳
🔹 Parents who saw road rage LESS likely to rate teen as bad driver — massive blind spot putting lives at risk 🙈💀
American teens NOT ready for the road. Where are the parents? 😬🛣️
#USNews#teensafety#driving
@america
J-j家j谱p- 家谱 The Family Tree (2011)
直达链接:https://pan.quark.cn/s/32c4d8126f28
#家谱#The Family Tree #Driving Lessons
链接:https://link3.cc/sf_com
#电影#喜剧#美国#10年代
🔥🏁Koenigsegg Regera Breaks Rimac Nevera's Record in 0-400-0 Challenge 🏁🔥
🏆 The music didn't play for long: Rimac Nevera's record in the 0-400-0 km/h acceleration-braking challenge lasted only a month. The Croatian hypercar surpassed the previous record holder, Koenigsegg Regera, clocking in at 29.94 seconds.
🇸🇪 The Swedish brand shrugged and sent the Regera back onto the track. Guess what? 28.81 seconds. How do you like that, Mate Rimac?
🥇 The margin of victory was 1.13 seconds, which in such a discipline, it must be said, is quite impressive. Surely, Rimac will have to respond. Competing is possible, but it will definitely require some effort.
🏎️Interestingly enough, the Regera has already been discontinued, with the last unit delivered to its owner in 2022. So why set a record with a car that is no longer in production? Koenigsegg answers bluntly: "Because it can!" The Regera remains superior to any newcomer. And it has proven it once again.
💥To outperform a significant rival - an electric car that has just set 23 records - is both impressive and beautiful. 💥
#Koenigsegg#Regera#driving#car