#!/usr/bin/env bash
set -euo pipefail
WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' EXIT
VERSION="Debian bookworm-slim GNU bash ${BASH_VERSION%%(*} (--network none)"
# Case 1: kernel_and_distro_identity
kernel_name=$(uname -s)
distro_id=$(awk -F= '$1=="ID"{gsub(/"/,"",$2); print $2}' /etc/os-release)
bash_major="${BASH_VERSINFO[0]}"
c1_actual="{\"kernel\":\"${kernel_name}\",\"distro_id\":\"${distro_id}\",\"bash_major\":${bash_major}}"
c1_expected='{"kernel":"Linux","distro_id":"debian","bash_major":5}'
c1_passed=$([ "$c1_actual" = "$c1_expected" ] && echo true || echo false)
# Case 2: posix_shell_and_core_tools
found_count=0
for tool in ls cp mv rm cat chmod mkdir; do
if command -v "$tool" >/dev/null 2>&1; then
found_count=$((found_count + 1))
fi
done
c2_actual="{\"core_tools_found\":${found_count}}"
c2_expected='{"core_tools_found":7}'
c2_passed=$([ "$c2_actual" = "$c2_expected" ] && echo true || echo false)
# Case 3: gpl_and_open_source_license_probe
gpl2_ok=false
gpl3_ok=false
[ -s /usr/share/common-licenses/GPL-2 ] && gpl2_ok=true
[ -s /usr/share/common-licenses/GPL-3 ] && gpl3_ok=true
distro_families=$(printf "Debian\nFedora\nopenSUSE\n" | wc -l | tr -d ' ')
c3_actual="{\"gpl2_present\":${gpl2_ok},\"gpl3_present\":${gpl3_ok},\"distro_families_listed\":${distro_families}}"
c3_expected='{"gpl2_present":true,"gpl3_present":true,"distro_families_listed":3}'
c3_passed=$([ "$c3_actual" = "$c3_expected" ] && echo true || echo false)
cat <<EOF
{
"version": "${VERSION}",
"cases": [
{
"name": "kernel_and_distro_identity",
"summary": "核对 Linux 内核标识、Debian 发行版标识及 GNU bash 5 主版本",
"expected": ${c1_expected},
"actual": ${c1_actual},
"passed": ${c1_passed}
},
{
"name": "posix_shell_and_core_tools",
"summary": "核对 7 个核心类 UNIX 命令在当前容器 PATH 中均可用",
"expected": ${c2_expected},
"actual": ${c2_actual},
"passed": ${c2_passed}
},
{
"name": "gpl_and_open_source_license_probe",
"summary": "核对 /usr/share/common-licenses 下 GPL-2 与 GPL-3 开源许可文本存在及主流发行版族统计",
"expected": ${c3_expected},
"actual": ${c3_actual},
"passed": ${c3_passed}
}
]
}
EOF
本例需在 本地离线 Docker 容器(debian:bookworm-slim,GNU bash 5.2.15,--network none)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:本地离线 Docker 容器(debian:bookworm-slim,GNU bash 5.2.15,--network none)。
入口文件:projects/linux-tutorial-lab/explore-tutorial.sh
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-tutorial.sh,或下载右侧课程工程包。 - 确认本地已准备 本地离线 Docker 容器(debian:bookworm-slim,GNU bash 5.2.15,--network none)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联32章) · 含当前章节或实例 · mbskycom202612a1487.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a1515.zip