您好,我如何使用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. If/then/else语句批量
- 2. MySQL IF THEN ELSE语句
- 3. SqlAlchemy:case语句(case - if - then -else)
- 4. 选择由IF-THEN-ELSE条件语句
- 5. VHDL程序IF-THEN-ELSE-if语句
- 6. R中的If-then-else语句
- 7. awk if-then-else语句错误
- 8. vbscripting:using或在If ... Then ... Else语句
- 9. if else if else语句(JS)
- 10. 的FxCop,查找“的if-else”语句
- 11. 找不到“if/else”语句
- 12. SCONS if/then语句
- 13. C++ if ... then语句
- 14. if then语句javascript
- 15. SAS IF then语句
- 16. 的if else语句
- 17. 使用csv文件的if-else语句
- 18. if/else语句
- 19. If else语句
- 20. if else语句
- 21. if-else语句
- 22. If/else语句
- 23. XML IF-THEN-ELSE
- 24. VHDL If/Else语句
- 25. 如何在Oracle的where子句中使用IF THEN ELSE语句?
- 26. Oracle IF/ELSE语句
- 27. 查找tibco中“Else”语句的免费“if”语句
- 28. 在if-then-else语句中的php语法
- 29. 条件if/else语句
- 30. Codeigniter If else语句条件
fi?意思。最后? – 2010-02-06 04:57:40
你的'test'语法是假的。 – 2010-02-06 05:03:52
对不起,省略了括号内的空格。 – danben 2010-02-06 14:50:03