【发布时间】:2025-12-22 13:55:07
【问题描述】:
我正在从https://unix.stackexchange.com/questions/494143/recursive-shell-script-to-list-files修改这个递归目录爬取脚本
我的计划只是连接我目录中文本文件输出的字符串
就像:content+= content + cat file.txt,我觉得我所拥有的并不算太远,但现在输出是空白的,我想我误解了如何将 cat 函数与字符串分开连接部分
我尝试使用 less 而不是 cat 但这会产生相同的结果我正在关注下面的链接但似乎没有一个示例为我产生输出 How to concatenate string variables in Bash
#! /bin/bash
echo "starting script"
content="start =>"
walk_dir () {
shopt -s nullglob dotglob
for pathname in "$1"/*; do
if [ -d "$pathname" ]; then
walk_dir "$pathname"
else
case "$pathname" in
*.txt|*.doc)
#printf '%s\n' "$pathname"
content+=(cat "$pathname") #add file contents to the previous string
esac
fi
done
echo "$content"
}
DIR=/c/Users/xxxx/Desktop/xxxx
walk_dir "$DIR"
对 bash 脚本很陌生,但是
【问题讨论】: