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
🏝Un paysage marin saisissant à Tung Ping Chau, à #Hong Kong, avec ses rares falaises sédimentaires et ses côtes sculptées par les vagues, attire des visiteurs
Les fines roches laminées de l'île se sont formées à partir de limon et de boue déposés dans un lac salé il y a environ 55 millions d'années. Elle abrite également plus de 60 espèces de coraux, ce qui en fait l'un des paysages géologiques les plus insolites de Hong Kong.
RT en français • Osez questionner !
#Canadian miner Allied Gold, operating in #Ethiopia, sold to China’s Zijin Gold in $4bn deal
Canadian gold mining company #Allied_Gold, which operates major projects in Ethiopia, has agreed to be acquired by #China’s #Zijin_Gold International in an all-cash deal valued at about $4 billion, according to a report by the Financial Times.
The transaction will see #Hong Kong–listed Zijin Gold International acquire Allied Gold for C$5.5 billion ($4 billion), as record-high gold prices continue to drive consolidation across the global mining sector, the Financial Times reported.
Allied Gold has mining operations in Ethiopia, Mali, and Côte d’Ivoire. The company welcomed the deal, which values its shares at C$44 apiece — a 27 percent premium to its 30-day average share price prior to the announcement. The surge reflects strong investor appetite for gold assets amid soaring bullion prices......
https://www.facebook.com/AddisstandardEng/posts/pfbid05VJM2KTLGsAio8Py1W1QkitgusnwrVRLfN489qhATq8qGYuLDA6CmsHam7XQY3t7l