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
🚀🚀Raining Profits in the Premium Group
🎯🎯#BAT/USDT has covered all the targets to give an amazing profit of 21% for all Premium Members
👁🗨Contact @futurechief to enter the premium group & make daily gains on Futures as well as Spot Market
#BAT/USDT analysis :
#BAT is in an uptrend, consistently making new highs while trading above the 200 EMA. Currently, the price is above the support zone and is expected to bounce back from this level, resuming its bullish momentum to test previous highs.
TF : 1D
Entry : $0.2250
Target : $0.2943
SL : $0.2027
#BAT/USDT analysis :
#BAT is presently consolidating within a channel. The overall trend on the larger timeframes indicates a bearish outlook, suggesting a potential breakout from the channel to continue moving downwards towards lower price levels. It is advisable to wait for a breakout of the channel and a decline below the $0.1564 level for a short position entry.
TF : 2H
Entry : $0.1564
Target : $0.1313
SL : $0.1640
#BAT/USDT analysis -
#BAT is currently in downtrend, trading below the 200 EMA. The price is in a pullback phase and is projected to test the resistance zone close to the 200 EMA before potentially dropping further to revisit the previous lows. It is recommended to await the price to test the zone before considering a short entry.
TF : 4h
Entry : $0.1970
Target : $0.1728
SL : $0.2067