我有这个脚本:
#!/bin/bash
function main {
while read -r file; do
do_something "$file"
done <<< $(find . -type f 2>/dev/null)
}
function do_something{
echo file:$@
}
Run Code Online (Sandbox Code Playgroud)
在 Linux 上,它工作正常,但在 Mac(Bash 版本 5.2)上,它将找到的所有文件视为一项,并将整个字符串不带换行符传递到do_something
. 如果我运行这个:
while read -r file; do
echo file:"$file"
done <<< $(find . -type f 2>/dev/null)
Run Code Online (Sandbox Code Playgroud)
直接在 Mac 上的 Bash 终端中也可以正常工作。那么出了什么问题呢?