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
Codex
A Lightweight coding agent that runs in your Linux terminal
🔗Links
- Requirements
- Installation
- Source code & more info
Organization: OpenAI
🏷 Tags: #AI#Linux#WSL#MacOS#Utilities#Coding
📰 Waydroid runs Android apps on Linux better than Windows ever ran them on WSA
The Windows Subsystem for Android (WSA) is history now. Microsoft caved in and killed the project, which angered a lot of users because it was one of the main highlights of the Windows 11 launch. Microsoft failed to anticipate the demand for running Android apps with Google Play Store support, and the option to only download apps via the Amazon Appstore didn’t appeal to a lot of users. I thought WSA would kill third-party Android emulators on...
🔗 Source: https://www.xda-developers.com/waydroid-runs-android-apps-on-linux-better-than-windows-wsa/
#android#linux
📰 Linux is the best way to run Android apps on your PC, and it's not close
Running Android apps on my PC used to feel wrong, but Linux makes them feel right at home, and it's better than any Winddows solution.
🔗 Source: https://www.xda-developers.com/linux-best-way-run-android-apps-on-pc-until-gaming/
#linux#android
[$] Objections to systemd age-attestation changes go overboard
systemd 项目拟在用户记录中添加出生日期字段,以帮助应用遵守年龄验证法规。这一改动引发社区强烈反对,甚至出现针对贡献者的恶意攻击和人肉搜索。实际上,该字段仅用于存储信息,并非强制验证。
原文链接:https://lwn.net/Articles/1064706/
#Linux#开源社区#隐私保护#系统管理
#AIGC
Read more
New NTFS File-System Driver Submitted For Linux 7.1
Linux 7.1 合并窗口迎来了一项重要更新:一个全新的、现代化的 NTFS 文件系统驱动程序已提交。Linus Torvalds 尚未确认是否会合并此驱动,但它看起来已准备就绪,旨在提供比现有的 NTFS3 驱动更好的 Linux NTFS 体验。当前的 NTFS3 驱动由 Paragon Software 几年前贡献至内核主线,但后续功能进展有限。
原文链接:https://www.phoronix.com/news/New-NTFS-Driver-Submitted-Linux
#Linux#内核#文件系统#NTFS
#AIGC
Read more