RedHat Linux文件系统的死循环?
我自己写了段简单的shell代码,用来查找文件。
在自己的主目录下执行一切正常。但如果我在根目录下执行,就会出现死循环。这是为什么?
源程序
#!/bin/sh
search()
{
for loop in $(ls );
do
if test -d $loop
then
if test "$loop" = "$1"
then
echo "$(pwd)/$loop/ is dir"
fi
cd $loop
search $1
cd ..
else
if test "$loop" = "$1"
then
echo "$(pwd)/$loop is file"
fi
fi
done
}
search $1
执行结果
[root@localhost /]search.sh *cob*
/home/test/callee.cob
/lib/modules/2.4.20-8/build/arch/mips/cobalt/ <dir>
/lib/modules/2.4.20-8/build/drivers/acpi/include/acobject.h
/lib/modules/2.4.20-8/build/drivers/char/joystick/cobra.c
/lib/modules/2.4.20-8/build/include/asm/cobalt.h
/lib/modules/2.4.20-8/build/include/asm-i386/cobalt.h
/lib/modules/2.4.20-8/build/include/asm-mips/cobalt/ <dir>
/lib/modules/2.4.20-8/build/include/linux/cobalt-nvram.h
/lib/modules/2.4.20-8/kernel/drivers/char/joystick/cobra.o
/opt/HILNGcbl/examples/CBLTOC/cobmain.cbl
/opt/HILNGcbl/examples/CTOCBL/cobolsub.cbl
/proc/1/cwd/home/test/callee.cob
/proc/1/cwd/lib/modules/2.4.20-8/build/arch/mips/cobalt/ <dir>
/proc/1/cwd/lib/modules/2.4.20-8/build/drivers/acpi/include/acobject.h
/proc/1/cwd/lib/modules/2.4.20-8/build/drivers/char/joystick/cobra.c
/proc/1/cwd/lib/modules/2.4.20-8/build/include/asm/cobalt.h
/proc/1/cwd/lib/modules/2.4.20-8/build/include/asm-i386/cobalt.h
/proc/1/cwd/lib/modules/2.4.20-8/build/include/asm-mips/cobalt/ <dir>
/proc/1/cwd/lib/modules/2.4.20-8/build/include/linux/cobalt-nvram.h
/proc/1/cwd/lib/modules/2.4.20-8/kernel/drivers/char/joystick/cobra.o
/proc/1/cwd/opt/HILNGcbl/examples/CBLTOC/cobmain.cbl
/proc/1/cwd/opt/HILNGcbl/examples/CTOCBL/cobolsub.cbl
就像标红的这个部分这样,每回在开头加上“/proc/1/cwd”的字样,不断地重复
检索其他目录时也遇到过类似的事:
[root@localhost usr]# search.sh *cob*
/usr/bin/htcobol
/usr/bin/mh/htcobol
/usr/bin/mh/mh/htcobol
/usr/bin/mh/mh/mh/htcobol
/usr/bin/mh/mh/mh/mh/htcobol
/usr/bin/mh/mh/mh/mh/mh/htcobol
/usr/bin/mh/mh/mh/mh/mh/mh/htcobol
/usr/bin/mh/mh/mh/mh/mh/mh/mh/htcobol
/usr/bin/mh/mh/mh/mh/mh/mh/mh/mh/htcobol
/usr/bin/mh/mh/mh/mh/mh/mh/mh/mh/mh/htcobol
/usr/bin/mh/mh/mh/mh/mh/mh/mh/mh/mh/mh/htcobol
.........................
这是怎么回事?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论