您好,我如何使用if/else语句来查找文件。比方说,如果我有一个file.txt
的根目录,我希望能够编写一个说明if [ file.txt ]
不存在的代码,然后使用find/-newer sshh > file.txt
或者使用[file.txt]
,然后在发生任何更改时邮寄更改。if then else语句查找文件
0
A
回答
2
在bash中,-f
会告诉你文件是否存在。
if [ -f /file.txt ];
then
// do something with mail
else
// do something with find
fi
0
你没有真正告诉我们很多关于你的平台,但恕我直言 - 如果你不知道该怎么做这样的事关你的头查找和基本的shell内建的顶部 - 你应该使用更高级的语言。这将更容易概念化和更容易维护。
将它作为一种学习体验 - 改变为使用python,perl或您选择的语言进行实验。
0
像这样的东西应该工作:
if test -e "file.txt"; then
cat file.txt | mail -s "file.txt changed" [email protected]
else
find/-newer sshh > file.txt
fi
但你很可能希望将其与diff
相结合,以找出是否在文件结构发生变化。
+1
你得到了“无用的猫”奖。 – 2010-02-06 16:03:17
+0
谢谢,如果它是一个奖项,它一定是好的:-) – 2010-02-06 23:57:18
相关问题
- 1. SqlAlchemy:case语句(case - if - then -else)
- 2. If/then/else语句批量
- 3. vbscripting:using或在If ... Then ... Else语句
- 4. R中的If-then-else语句
- 5. if else if else语句(JS)
- 6. 找不到“if/else”语句
- 7. if then语句javascript
- 8. SAS IF then语句
- 9. C++ if ... then语句
- 10. SCONS if/then语句
- 11. 的if else语句
- 12. If else语句
- 13. If/else语句
- 14. if else语句
- 15. XML IF-THEN-ELSE
- 16. Pexpect if else语句
- 17. 如何在Oracle的where子句中使用IF THEN ELSE语句?
- 18. Oracle IF/ELSE语句
- 19. 查找tibco中“Else”语句的免费“if”语句
- 20. SQL查询内嵌的if else语句
- 21. “形” - if-else语句
- 22. jquery if else语句
- 23. Python if else语句
- 24. PHP if/else语句
- 25. if else语句php
- 26. IF ELSE语句php
- 27. if和else语句
- 28. Big if else语句
- 29. jquery if else语句
- 30. PHP if else语句
fi?意思。最后? – 2010-02-06 04:57:40
你的'test'语法是假的。 – 2010-02-06 05:03:52
对不起,省略了括号内的空格。 – danben 2010-02-06 14:50:03