QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1303|回复: 15

大家看看这个脚本错在哪

[复制链接]
发表于 2003-6-26 21:24:39 | 显示全部楼层 |阅读模式
cat a
#!/bin/bash
echo "keyword:"
read keyword
echo "directory:"
read directory
dir -R $directory | (while read file;
do
grep " $keyword " $file
done
)
发表于 2003-6-26 22:33:02 | 显示全部楼层
is it something wrong when you run this shell?
回复

使用道具 举报

发表于 2003-6-26 23:56:50 | 显示全部楼层
对呀,错的时候有什么提示?
回复

使用道具 举报

 楼主| 发表于 2003-6-27 16:24:33 | 显示全部楼层
keyword:
yes
directory:
/etc/sysconfig
grep: /etc/sysconfig:: 没有那个文件或目录
grep: apmd: 没有那个文件或目录
grep: gpm: 没有那个文件或目录
grep: iptables: 没有那个文件或目录
grep: network-scripts: 没有那个文件或目录
grep: sendmail: 没有那个文件或目录
grep: apm-scripts: 没有那个文件或目录
grep: grub: 没有那个文件或目录
grep: irda: 没有那个文件或目录
grep: ntpd: 没有那个文件或目录
grep: static-routes: 没有那个文件或目录
grep: authconfig: 没有那个文件或目录
grep: harddisks: 没有那个文件或目录
grep: keyboard: 没有那个文件或目录
grep: pcmcia: 没有那个文件或目录
grep: syslog: 没有那个文件或目录
grep: clock: 没有那个文件或目录
grep: hwconf: 没有那个文件或目录
grep: kudzu: 没有那个文件或目录
grep: rawdevices: 没有那个文件或目录
grep: xinetd: 没有那个文件或目录
grep: console: 没有那个文件或目录
grep: i18n: 没有那个文件或目录
grep: mouse: 没有那个文件或目录
grep: redhat-config-users: 没有那个文件或目录
grep: desktop: 没有那个文件或目录
grep: init: 没有那个文件或目录
grep: network: 没有那个文件或目录
grep: redhat-logviewer: 没有那个文件或目录
grep: firstboot: 没有那个文件或目录
grep: installinfo: 没有那个文件或目录
grep: networking: 没有那个文件或目录
grep: rhn: 没有那个文件或目录
回复

使用道具 举报

发表于 2003-6-27 16:57:43 | 显示全部楼层
权限够吗?
回复

使用道具 举报

发表于 2003-6-27 18:14:58 | 显示全部楼层
没有权限
回复

使用道具 举报

 楼主| 发表于 2003-6-27 21:47:32 | 显示全部楼层
chmod 747 filename
回复

使用道具 举报

 楼主| 发表于 2003-6-28 01:11:54 | 显示全部楼层
cat a
#!/bin/bash
echo "keyword:"
read keyword
echo "directory:"
read directory
grep -R $keyword $directory
done
回复

使用道具 举报

发表于 2003-6-28 08:35:15 | 显示全部楼层
你用done干吗?
回复

使用道具 举报

 楼主| 发表于 2003-6-28 17:57:54 | 显示全部楼层
我是莱鸟。

原来是不用done的
回复

使用道具 举报

发表于 2003-6-28 17:59:28 | 显示全部楼层
你不用循环done就不用了吧!
回复

使用道具 举报

 楼主| 发表于 2003-6-29 09:52:08 | 显示全部楼层
用循环不是用fi结束`的吗?
回复

使用道具 举报

发表于 2003-6-29 18:51:07 | 显示全部楼层
[quote:fdc3d00f96="powerme"]用循环不是用fi结束`的吗?[/quote]
if是用fi结束的!
回复

使用道具 举报

发表于 2003-7-3 23:49:25 | 显示全部楼层
第一个帖子中的问题在于管道会启动新的 shell 进程,更不用说你还加了一对括号,这样前面的 $keyword 是不会传递到后面的 while 循环中的。解决的办法是把 while 写到当前的 shell 中执行:

#!/bin/bash
echo "keyword:"
read keyword
echo "directory:"
read directory
while read file;
do
grep " $keyword " $file
done < dir -R $directory

参考 http://www.linuxforum.net/forum/showflat.php?Cat=&Board=vrml&Number=411233&page=&view=&sb=&o=&vc=1
回复

使用道具 举报

 楼主| 发表于 2003-7-6 15:30:46 | 显示全部楼层
不行 提示错误


done < dir -R $directory
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-20 15:21 , Processed in 0.045748 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表