问题在一个bash脚本查找功能的结果 [英] Issue with result of a find function in a bash script
问题描述
我有在bash脚本中的问题。我的函数使用查找功能的结果。
I have a problem with a script in bash. My for function is using the results of the find function.
长话短说:在SSH,发现该函数返回2结果并在bash脚本一个结果。
Long story short: in SSH, find the function returns 2 results and in a bash script a single result.
我尝试以下两个$ C $的CS。
I tried both of the following codes.
for f in $(find $path -name *.properties)
do
echo $f
done
或
list=$(find $path -name *.properties)
for f in $list;
do
echo $f
done
在指定的路径有几个文件夹和文件,两个文件中有我要找的扩展。如果我在SSH运行这些命令中的一个,我觉得这两个文件,但是,如果我从一个bash脚本运行命令的结果中包含一个单一的文件。
In the specified path there are several folders and files, two of the files have the extension that i am looking for. If I run one of these commands in SSH I find both files, but if I run the command from a bash script the result contains a single file.
该为功能工作正常,问题是查找功能。我运行下面的code在脚本bash和我仍然有一个结果。
The for function is working fine, the problem is the find function. I run the following code in a script bash and i still have one result.
list=$(find $path -name *.properties)
echo $list
我运行SSH以下code,我发现两个文件:
I run the following code in SSH and I found 2 files:
[root@was85 ~]# for f in $(find $path/temp/ -name *.properties); do echo $f
> done
谁能帮我?
感谢您!
推荐答案
如果使用 BASH
更好地利用这个,而
使用进程替换
和环路的适当引用并使用 -print0
选项:
If using BASH
better to use this while
loop using process substitution
and proper quoting and use -print0
option:
while IFS= read -rd '' f; do
echo "$f"
done < <(find "$path" -name '*.properties' -print0)
这篇关于问题在一个bash脚本查找功能的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!