watch_1394 发表于 2004-10-19 09:44:13

这个脚本中的if语句是什么意思?

#!/bin/bash

for file in ./*
do
if grep -s echo $file >> test.txt
then :
fi
done

exit 0

if grep -s echo $file >> test.txt 这句是什么意思,高手们能够给我仔细讲讲吗?我查了好多资料都没有收获.
谢谢

jerry_cym 发表于 2004-10-19 10:51:26

grep是查找字符串,有可能是查找到显示$file的内容,然后追加到test.txt的文件中去,也许是这样吧!

MichaelBibby 发表于 2004-10-19 14:26:28


$ man grep
-s, --no-messages
    禁止输出关于文件不存在或不可读的错误信息。对于可移植性需要注意:与 GNU grep 不同,传统的 grep 不遵守 POSIX.2 规范,因为传统的 grep 缺少一个 -q 选项,而它的 -s 选项与 GNU grep 的 -q 选项行为相似。需要可移植到传统 grep 的 shell 脚本应当避免使用 -q 和 -s 选项,而应当将输出重定向到 /dev/null 。

isun 发表于 2004-10-19 17:49:48

多余

MichaelBibby 发表于 2004-10-19 17:53:24

多余
好久不见啊,isun兄 :oops:
页: [1]
查看完整版本: 这个脚本中的if语句是什么意思?