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
🇧🇩#Bangladesh – Il National Citizen Party (#NCP), fondato dagli studenti Gen Z che hanno portato alla caduta dell’ex premier Sheikh #Hasina, si coalizzerà con i partiti islamisti in vista delle elezioni di febbraio. Diversi dirigenti e candidati riformisti si sono dimessi in seguito alla decisione che potrebbe portare il clero islamico al governo.
@UltimoraPolitics24
News: Former #Sudan PM Hamdok says Islamist factions major obstacle to ending war
Abdalla Hamdok, Former Sudanese Prime Minister and head of the Somoud civilian coalition, has said Islamist factions linked to Sudan’s former ruling party are among the main obstacles to ending the country’s nearly three-year civil war, according to a report by Abu Dhabi-based newspaper The National.
Speaking to the newspaper on the sidelines of the 39th African Union summit in #Addis_Abeba, Hamdok said Islamist groups and the National Congress Party (#NCP) — the political party of ousted president Omar Al Bashir — remains key actors resisting peace initiatives and efforts to reach a broader national consensus.
He also criticized Sudan’s army chief, Gen Abdel Fattah #Al_Burhan, for insisting on a military solution to defeat the rival Rapid Support Forces (#RSF). Al Burhan has publicly ruled out peace....
https://web.facebook.com/AddisstandardEng/posts/pfbid02qycixQfoRJLo5F9EWtxgsymfNbxMqUa9D4Qquz6X3DjfUBUFxig1b3xTGb3MzEHHl
🇧🇩#Bangladesh – Oggi oltre 120 milioni di cittadini sono stati chiamati alle urne per rinnovare i 350 seggi del Parlamento, le prime elezioni dopo la deposizione della premier Sheikh #Hasina e la messa al bando della Lega Awami. Si sono sfidati il Partito Nazionalista Bengalese (#BNP) di Tarique #Rahman (rientrato dall’esilio a Londra dopo 17 anni), di centro-destra, per la liberalizzazione dell’economia, vicino alla classe media e all’esercito, e la coalizione guidata dal partito islamista Jamaat-e-Islami (#Jamaat) di Shafiqur #Rahman, che punta a introdurre la sharia nel Paese. La coalizione include il Partito Nazionale dei Cittadini (#NCP), fondato dai leader delle proteste studentesche, ma l’alleanza con gli islamisti è stata fortemente contestata da donne, laici e minoranza indù che avevano sostenuto le proteste. Risultati nelle prossime ore.
@UltimoraPolitics24