首页 > 解决方案 > 为什么在 shell 脚本中打印空路径?

问题描述

filter_option=" -name \"*\" "
file_paths=$(find "." -type f $filter_option)
echo find "." -type f $filter_option
echo $file_paths

samuel@:~/.../linux$ ./test.sh
找到 . -type f -name "*"

塞缪尔@:~/.../linux$

我该如何解决这个问题以获得find . -type f -name "*"'s 结果?

标签: linuxbashshellsh

解决方案


我建议使用数组:

filter_option=(-name '*')
file_paths=$(find "." -type f "${filter_option[@]}")

推荐阅读