【发布时间】:2013-04-05 08:49:31
【问题描述】:
脚本目标很简单。
我有很多目录,其中包含一些捕获的流量文件。 我想为每个目录运行一个命令。所以我想出了一个脚本。但我不知道为什么脚本只在第一个匹配时运行。
#!/bin/bash
# Collect throughput from a group of directory containing capture files
# Group of directory can be specify by pattern
# Usage: ./collectThroughputList [regex]
# [regex] is the name pattern of the group of directory
for DIR in $( ls -d $1 ); do
if test -d "$DIR"; then
echo Collecting throughputs from directory: "$DIR"
( sh collectThroughput.sh $DIR > $DIR.txt )
fi
done
echo Done\!
我试试:
for DIR in $1; do
或
for DIR in `ls -d $1`; do
或
for DIR in $( ls -d "$1" ); do
或
for DIR in $( ls -d $1 ); do
但结果是一样的。 for 循环只运行一次。
最后我找到了这个并做了一些技巧让它工作。但是,我想知道为什么我的第一个脚本不起作用。
find *Delay50ms* -type d -exec bash -c "cd '{}' && echo enter '{}' && ../collectThroughput.sh ../'{}' > ../'{}'.txt" \;
"*Delay*" 是我要运行命令的目录模式名称。 感谢您指出问题。
【问题讨论】: