TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #411 · 9 фев.

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

Резултати

Пронајдени 7 слични објави

Пребарај: #stoplassafever

当前筛选 #stoplassafever清除筛选

Here are some ways to keep your food safe from rodents⬇️ ✅Store your food in tightly covered containers ✅Clean your environments regularly ✅Put rodent repellents around your food store ✅Seal all cracks, gaps, or holes in your homes to prevent entry of rodents #STOPLassaFever

Rats and mice constantly urinate & defaecate, contaminating every surface they touch Keep your homes & communities clean to prevent direct or indirect contact with rats ➡️Properly dispose of waste from your homes ➡️Do not defecate in open areas ➡️Sweep your floors regularly, removing crumbs or food remnants #STOPLassaFever

Not all fevers are malaria! Report early to a healthcare facility when experiencing #LassaFever-associated symptoms. Early symptoms of #LassaFever include fever, body weakness, sore throat, muscle & chest pain, nausea, vomiting, diarrhoea, cough & abdominal pain. #STOPLassaFever

🛑 Lassa Fever is highly infectious! Your hands can carry more than you think — keep them clean to stay safe. 🧼 Wash regularly with soap under running water. 💪 Protect yourself. Protect others. #LassaFever#HygieneIsKey#NCDCNigeria#StopLassaFever