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
📰The EU is betting over €1 million that KDE can challenge Microsoft's desktop dominance
The technological world of the European Union has been having a major shake-up recently. Rattled by how much they depend on proprietary software in key areas of government and public services, the EU has been working toward breaking free from closed-source software and moving toward more open-source options. For instance, France's government is ditching Windows for Linux after calling US tech dependence a strategic risk.
🔗 Source: https://www.xda-developers.com/the-eu-is-betting-1-million-that-kde-can-challenge-microsofts-desktop-dominance/
#kde#linux#opensource
📰 Rocky Linux Becomes a KDE Patron
Rocky Linux has become a KDE patron, joining organizations like Canonical, Google, and SUSE in supporting the KDE open-source ecosystem.
🔗 Source: https://linuxiac.com/rocky-linux-becomes-a-kde-patron/
#linux#opensource#kde
📰 Dell XPS 13 Snapdragon Elite Laptop Sees New EC Linux Driver To Improve Support
Last month Dell upstreamed the firmware needed for their XPS 13 935 Snapdragon X1 Elite laptop. This makes the Linux outlook for this ARM-based Dell XPS laptop much better than before in not having to worry about extracting necessary firmware blobs from Windows 11. Now another step forward for the Dell XPS 13 9345 is being made with a new EC driver being posted to enhance the hardware support...
🔗 Source: https://www.phoronix.com/news/Dell-XPS-13-9345-EC-Driver
#arm#linux
GNU C Library 2.43 released
GNU C 标准库 glibc 发布了 2.43 版本。主要更新内容包括:新增对 `mseal()` 和 `openat2()` 系统调用的支持;提供了使用 Clang 编译器进行构建的实验性支持;升级至 Unicode 17.0.0 标准;并包含多项安全修复及其他改进。
原文链接:https://lwn.net/Articles/1055757/
#Glibc#Linux#编程#系统软件
#AIGC
Read more
[$] As ye clone(), so shall ye AUTOREAP
Linux 内核进程管理机制近年来持续演进,主要驱动力来自 pidfd API 的引入。pidfd 是一个指向进程的文件描述符,相比传统的进程 ID,它能更明确、更安全地标识进程。
近期,pidfd 相关工作的主要推动者 Christian Brauner 提议为 `clone3()` 系统调用新增两个标志位。其中一项提议以某种有争议的方式改变了内核的安全模型。
原文链接:https://lwn.net/Articles/1059673/
#Linux#内核开发#进程管理#系统编程
#AIGC
Read more
JADX is a powerful open-source tool that enables users to decompile Android applications, converting Dalvik bytecode into readable Java source code. This facilitates in-depth analysis and understanding of APK, DEX, AAR, AAB, and ZIP files, offering developers and security researchers enhanced transparency and control over application code.
🔗 Links:
- Download
- Screenshots
- Features
- Source Code
- Developer: skylot
❗️Friendly reminder:
If you find it useful, You may star the repo, donate to the developer, or perhaps you may also contribute to the development of this project.
🏷 Tags: #Windows#MacOS#Linux#Decompiler#OpenSource#Utilities