32 lines
651 B
Bash
Executable File
32 lines
651 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# 输出文件名
|
|
output_file="combined.md"
|
|
|
|
# 清空或创建输出文件
|
|
> "$output_file"
|
|
|
|
# 遍历 1.c 到 20.c
|
|
for i in {1..20}; do
|
|
file="${i}.c"
|
|
|
|
# 检查文件是否存在
|
|
if [[ -f "$file" ]]; then
|
|
# 添加标题
|
|
echo "### C语言-${i}" >> "$output_file"
|
|
|
|
# 添加代码块开始
|
|
echo '```c' >> "$output_file"
|
|
|
|
# 将文件内容直接追加到输出文件(视为 GB2312 编码)
|
|
cat "$file" >> "$output_file"
|
|
|
|
# 添加代码块结束
|
|
echo '```' >> "$output_file"
|
|
|
|
# 添加一个空行
|
|
echo "" >> "$output_file"
|
|
else
|
|
echo "文件 $file 不存在,跳过。"
|
|
fi
|
|
done |