initiate () {
read -p "Location(s) to look for .bsp files in? " loc
find $loc -name "*.bsp" | while read
do
if [ -f "$loc.bz2" ]
then
continue
else
filcount=$[$filcount+1]
bzip $loc
fi
if [ "$scan" == "1" ]; then bzipint $loc
fi
echo $filcount #Correct counting
echo $zipcount #Correct counting
echo $scacount #Correct counting
echo $valid #Equal to 1
done
echo $filcount #Reset to 0
echo $zipcount #Reset to 0
echo $scacount #Reset to 0
echo $valid #Still equal to 1
}
我正在编写一个 bash shell 脚本来使用bzip2
拉上所有拉链.bsp
目录内的文件。在此脚本中,我有几个用于计算总数的变量(文件、成功的 zip、成功的完整性扫描),但是我似乎遇到了问题。
When find $loc -name "*.bsp"
没有文件可以提供while read
and while read
退出,它归零$filcount
, $zipcount
and $scacount
(所有这些都在里面改变(增加)initiate ()
, bzip ()
(在期间调用initiate ()
) or bzipint ()
(这也被称为initiate ()
).
为了测试是否与内部变量变化有关initiate ()
或从它访问的其他功能,我使用了 echo$valid
,它是在外部定义的initiate ()
(like $filcount
, $zipcount
等),但没有从内部的另一个函数改变initiate ()
或里面initiate ()
本身。
有趣的是,$valid
不会像 initiate 中的其他变量一样重置为 0。
谁能告诉我为什么当读取退出时我的变量会神奇地重置?
如果你使用bash
while read
do
if [ -f "$REPLY.bz2" ]
then
continue
else
filcount=$[$filcount+1]
bzip $REPLY
fi
if [ "$scan" == "1" ]; then bzipint $REPLY
fi
echo $filcount #Correct counting
echo $zipcount #Correct counting
echo $scacount #Correct counting
echo $valid #Equal to 1
done < <(find $loc -name "*.bsp")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)