将num 设为2 ,并在/root/mydir下建2个文件,为什么该函数并不会结束?

#!/bin/bash
read -p "num=" num
fileNum(){
while true
do
array1=(`ls /root/mydir`)
factnum=${#array1[@]}
echo $factnum
if [ $num -eq $factnum ];then
break
fi
done
}
fileNum &
在一个shell中后台运行函数fileNum,当/root/mydir目录下文件的数量达到预先设定的$num时,退出函数。
问题:例如,将num 设为2 ,并在/root/mydir下建2个文件,但是该函数并不会结束,为什么呢?谢谢!

喵喵时光机
浏览 169回答 1
1回答

紫衣仙女

比面shell脚本文件:#===========test.sh! /bin/shecho_line(){ echo date echo "Wellcome to shell func!"}echo_hello(){ echo "Hello World!"}#======================shell调用两函数啊我用【./test.sh echo_hello】却没输我已经给test.sh加执行权限请问envsetup.sh边function gettop(){local TOPFILE=build/core/envsetup.mkif [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; thenecho $TOPelseif [ -f $TOPFILE ] ; then# The following circumlocution (repeated below as well) ensures# that we record the true directory name and not one that is# faked up with symlink names.PWD= /bin/pwdfi}并没返值调用何获取参数 T=$(gettop)实际参数谢谢
打开App,查看更多内容
随时随地看视频慕课网APP