LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: seamonkey

zsh

[复制链接]
 楼主| 发表于 2006-7-6 12:00:22 | 显示全部楼层
我也糊涂了

getconf ARG_MAX
131072

这个是指131072 byte,是不是?

那么
perl -e 'print "x " x 32768' | wc -c
65536

ls `perl -e 'print "x " x 32768'
zsh: argument list too long: ls

ls `perl -e 'print "x " x 32767'`
zsh: argument list too long: ls

ls `perl -e 'print "x " x 32766'`
ls: x: No such file or directory
...
...

这么看来,是不能超过65536个byte?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-6 12:04:24 | 显示全部楼层
echo /usr/include/**/*.h | wc -c
71228

这又是怎么回事?
回复 支持 反对

使用道具 举报

发表于 2006-7-6 12:13:34 | 显示全部楼层
Post by seamonkey
我也糊涂了

getconf ARG_MAX
131072

这个是指131072 byte,是不是?

那么
perl -e 'print "x " x 32768' | wc -c
65536

ls `perl -e 'print "x " x 32768'
zsh: argument list too long: ls

ls `perl -e 'print "x " x 32767'`
zsh: argument list too long: ls

ls `perl -e 'print "x " x 32766'`
ls: x: No such file or directory
...
...

这么看来,是不能超过65536个byte?

恩,是啊.是不是预留了一半给env variables?还有就是这个limit是linux内核指定,和用什么shell没有关系。所以我想如果globbing扩展后实际参数超过这个限制,那zsh也应是不行的。那样的话,递归"**/*.h"是怎么实现的呢?
回复 支持 反对

使用道具 举报

发表于 2006-7-6 12:17:57 | 显示全部楼层
Post by seamonkey
echo /usr/include/**/*.h | wc -c
71228

这又是怎么回事?

呵呵,是啊。都串在一行了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-6 12:24:48 | 显示全部楼层
我发现讨论过这个问题,当时我不知道为什么直接把65536 * 2了,把字符都当成双字节了?真是没经过脑子。

http://www.linuxsir.cn/bbs/showthread.php?t=255837
回复 支持 反对

使用道具 举报

发表于 2006-7-6 12:28:31 | 显示全部楼层
做了一个短的测试
  1. under bash: grep bin /etc/**/*.sh >/tmp/bash.grep
  2. under zsh: grep bin /etc/**/*.sh >/tmp/zsh.grep
  3. diff -burN /tmp/bash.grep /tmp/zsh.grep
复制代码
从我的结果看,bash显然是支持递归globbing的。但是结果又不是完全一样,非常奇怪的是bash递归了所以但剩下了一个目录,而zsh确是老老实实的查询的所有。看样子还是zsh强些。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-6 12:37:30 | 显示全部楼层
不过似乎/etc的子目录大多不会超过一层,只有少数例外。比如/etc/udev/rules.d

bash:
  1. grep KERNEL /etc/**/*.rules | cut -d: -f1 | uniq
  2. /etc/udev/alsa-utils.rules
  3. /etc/udev/cd-aliases-generator.rules
  4. /etc/udev/cd-aliases.rules
  5. /etc/udev/compat-full.rules
  6. /etc/udev/compat.rules
  7. /etc/udev/devfs.rules
  8. /etc/udev/hdparm.rules
  9. /etc/udev/permissions.rules
  10. /etc/udev/persistent-input.rules
  11. /etc/udev/persistent-net-generator.rules
  12. /etc/udev/persistent.rules
  13. /etc/udev/run.rules
  14. /etc/udev/udev.rules
  15. /etc/udev/xserver-xorg-input-wacom.rules
复制代码


zsh:
  1. /etc/udev/alsa-utils.rules
  2. /etc/udev/cd-aliases-generator.rules
  3. /etc/udev/cd-aliases.rules
  4. /etc/udev/compat-full.rules
  5. /etc/udev/compat.rules
  6. /etc/udev/devfs.rules
  7. /etc/udev/hdparm.rules
  8. /etc/udev/permissions.rules
  9. /etc/udev/persistent-input.rules
  10. /etc/udev/persistent-net-generator.rules
  11. /etc/udev/persistent.rules
  12. /etc/udev/rules.d/020_permissions.rules
  13. /etc/udev/rules.d/udev.rules
  14. /etc/udev/rules.d/z20_persistent-input.rules
  15. /etc/udev/rules.d/z20_persistent.rules
  16. /etc/udev/rules.d/z45_persistent-net-generator.rules
  17. /etc/udev/rules.d/z50_run.rules
  18. /etc/udev/rules.d/z60_alsa-utils.rules
  19. /etc/udev/rules.d/z60_hdparm.rules
  20. /etc/udev/rules.d/z60_xserver-xorg-input-wacom.rules
  21. /etc/udev/rules.d/z75_cd-aliases-generator.rules
  22. /etc/udev/run.rules
  23. /etc/udev/udev.rules
  24. /etc/udev/xserver-xorg-input-wacom.rules
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-7-6 13:48:56 | 显示全部楼层
我的/etc下还是有不少多层的,比如我把vim的runtime放到了/etc,还有/etc/skel下,不过**/*.sh的形式好像并不包括以"."卡头的目录。我的/etc/skel下有.目录下有sh文件,但都查不着。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-6 13:52:36 | 显示全部楼层
那么你是说bash能递归?
回复 支持 反对

使用道具 举报

发表于 2006-7-6 23:27:51 | 显示全部楼层
Post by seamonkey
那么你是说bash能递归?
认真比较了一下,好象真的是不行。bash只能将命令扩展到一层目录,无论在什么情况下。在比较只有一层目录时看不出来,当比较包含多层目录时就看出来了,bash没有历遍的正是那些多层目录。你是对的。
回复 支持 反对

使用道具 举报

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

本版积分规则

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