虽然测试循环,如果一个文件在bash存在 [英] While loop to test if a file exists in bash
本文介绍了虽然测试循环,如果一个文件在bash存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的一个shell脚本,做一个txt文件,只有当它确实存在,但是本次测试循环不起作用一定的变化,我不知道为什么?
谢谢!
而[! -f /tmp/list.txt];
做
睡眠2
DONE
解决方案
当你说不工作,你怎么知道这是行不通的?
您可以尝试找出该文件实际上存在添加:
而[! -f /tmp/list.txt]
做
睡眠2
DONE
ls -l命令/tmp/list.txt
您也可以确保您使用的是击(或相关)的外壳通过键入'回声$ SHELL。我认为CSH和TCSH使用略有不同的语义这个循环。
I'm working on a shell script that does certain changes on a txt file only if it does exist, however this test loop doesn't work, I wonder why? Thank you!
while [ ! -f /tmp/list.txt ] ;
do
sleep 2
done
解决方案
When you say "doesn't work", how do you know it doesn't work?
You might try to figure out if the file actually exists by adding:
while [ ! -f /tmp/list.txt ]
do
sleep 2
done
ls -l /tmp/list.txt
You might also make sure that you're using a Bash (or related) shell by typing 'echo $SHELL'. I think that CSH and TCSH use a slightly different semantic for this loop.
这篇关于虽然测试循环,如果一个文件在bash存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文