LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 898|回复: 7

请问 find ~/* -type f | tee >(grep '.htm*$' > ~/.shds/html-s

[复制链接]
发表于 2005-8-16 04:13:27 | 显示全部楼层 |阅读模式
find ~/* -type f | tee >(grep '.htm*$' > ~/.shds/html-s ) \
  >(grep '.doc$' > ~/.shds/doc-s ) \
  >/dev/null
在 终端里直接执行没有问题

但是 写在脚本里就出错

hua@hua:~$  ./find.sh
./find.sh: line 3: syntax error near unexpected token `('
./find.sh: line 3: `find ~/* -type f | tee >(grep '.htm*$' > ~/.shds/html-s ) \'
发表于 2005-8-16 11:45:56 | 显示全部楼层
Post by jhuangjiahua
find ~/* -type f | tee >(grep '.htm*$' > ~/.shds/html-s ) \
  >(grep '.doc$' > ~/.shds/doc-s ) \
  >/dev/null


开头的 > 是什么?手工输入的符号?PS2?

试着把这个长长的命令写在一行,看看有没有语法问题。
回复 支持 反对

使用道具 举报

发表于 2005-8-16 11:47:58 | 显示全部楼层
是不是指这个?
  1. find ~/* -type f | tee file1 | grep '.htm*$' > ~/.shds/html-s
  2. cat file1 | grep '.doc$' > ~/.shds/doc-s
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-16 14:00:30 | 显示全部楼层
> 是手工输入的
>()  是进程替换


  1. hua@hua:jinduck$ ps | tee   >(tr pts PPP)   >(tr pts SSS)
  2.   PID TTY          TIME CMD
  3. 5607 pts/0    00:00:00 bash
  4. 5646 pts/0    00:00:00 ps
  5. hua@hua:jinduck$   PID TTY          TIME CMD
  6. 5607 PPP/0    00:00:00 baPh
  7. 5646 PPP/0    00:00:00 PP
  8.   PID TTY          TIME CMD
  9. 5607 SSS/0    00:00:00 baSh
  10. 5646 SSS/0    00:00:00 SS

  11. hua@hua:jinduck$
复制代码






我上面输入的是

  1. find ~/* -type f | tee     >(grep '.htm*$' > ~/.shds/html-s )      >(grep '.doc$' > ~/.shds/doc-s )      >/dev/null
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-8-16 15:28:49 | 显示全部楼层
看上去 Process Substitution 是 bash 对 Shell 的扩展,它并不是 POSIX Shell 的内容。因此,我想你的 find.sh 是以 #!/bin/sh 开头而不是以 #!/bin/bash 开头的。我试过了,如果以 bash 模式执行,你的程序是没有问题的。
回复 支持 反对

使用道具 举报

发表于 2005-8-16 15:38:11 | 显示全部楼层
#!/bin/bash

find ~/* -type f | tee >(grep '.htm*$' > /tmp/html-s) \
>(grep '.doc$' > /tmp/doc-s ) \
>/dev/null


我的这个没错啊
/tmp/doc-s and /tmp/html-s两个文件中的内容也正常啊
回复 支持 反对

使用道具 举报

发表于 2005-8-16 18:35:24 | 显示全部楼层
sh不支持进程替换,bash支持!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-16 20:26:24 | 显示全部楼层
谢谢

换成 #!/bin/bash  就可以了.................

可能有些同情以前的 UNIX 上没有 bash 用的人.......
回复 支持 反对

使用道具 举报

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

本版积分规则

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