我有以下 Bash 脚本:
#!/bin/bash
cd ~/Library/Developer/CoreSimulator/Devices/;
files=$(find . -name iaGambro_gambro.sql)
select file in $files; do
if [ -n "$files" ]; then
sudo sqlite3 -header -column "${file}"
fi
break
done
它应该返回以下 2 个结果:
1) ./2EFF5EBF2B2D/Library/Private Documents/iaGambro_gambro.sql
2) ./A1AF3463BFD2/Library/Private Documents/iaGambro_gambro.sql
但由于 中的空格,它返回以下 4 Private Documents
:
1) ./2EFF5EBF2B2D/Library/Private
2) Documents/iaGambro_gambro.sql
3) ./A1AF3463BFD2/Library/Private
4) Documents/iaGambro_gambro.sql
如何让选择识别带有空格的路径?
笔记:我正在寻找如何在给定路径上执行,而不仅仅是打印出来
答案1
您可以使用find ... -exec
选项:
find . -name iaGambro_gambro.sql -exec bash -c '
select file do
: Do something with "$file"
break
done
' bash {} +