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

Резултати

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

Пребарај: #inspirational

当前筛选 #inspirational清除筛选
₿usiness Tips | Thoughts 💡

@quotesofzday · Post #269 · 07.08.2022 г., 12:01

Remember, Most of your stress comes from the way you respond, not the way life is. Adjust your attitude. Change how you see things. Look for the good in all situations. Take the lesson and find new opportunities to grow. Let all the extra stress, worrying, and overthinking go. #Inspirational

₿usiness Tips | Thoughts 💡

@quotesofzday · Post #268 · 07.08.2022 г., 11:59

Prioritize your mental and spiritual wellness. Do things that make you happy. Take time to nurture yourself. Don’t rush the process. Don’t judge where you’re at or where you think you should be. Just be kind and patient with yourself. Things are unfolding for you. #Inspirational

₿usiness Tips | Thoughts 💡

@quotesofzday · Post #258 · 05.08.2022 г., 16:01

Wrinkles, scars, imperfections, strengths, & weaknesses - all these made you who you are today - a strong, independent, beautiful human being. Embrace it all with gratitude. When you learn to accept & love everything about you, nobody can ever use it against you. #Inspirational

Quiet World 🍁

@QuietWorld · Post #7360 · 08.06.2020 г., 03:15

“𝕋𝕠 𝕤𝕦𝕔𝕔𝕖𝕖𝕕, 𝕪𝕠𝕦 𝕨𝕒𝕟𝕥 𝕥𝕠 𝕓𝕖 𝕒𝕓𝕝𝕖 𝕥𝕠 𝕣𝕖𝕘𝕦𝕝𝕒𝕥𝕖 𝕪𝕠𝕦𝕣 𝕚𝕞𝕡𝕦𝕝𝕤𝕖𝕤 𝕨𝕙𝕚𝕝𝕖 𝕒𝕝𝕤𝕠 𝕙𝕒𝕧𝕚𝕟𝕘 𝕥𝕙𝕖 𝕚𝕞𝕒𝕘𝕚𝕟𝕒𝕥𝕚𝕠𝕟 𝕥𝕠 𝕤𝕖𝕖 𝕨𝕙𝕒𝕥 𝕥𝕙𝕖 𝕗𝕦𝕥𝕦𝕣𝕖 𝕨𝕚𝕝𝕝 𝕓𝕖 𝕝𝕚𝕜𝕖 𝕚𝕗 𝕪𝕠𝕦 𝕥𝕣𝕪 𝕤𝕠𝕞𝕖𝕥𝕙𝕚𝕟𝕘 𝕟𝕖𝕨.” #selfreminder#motivation#inspirational#life#wisdom#success @quietworld🍃