linux - "For" loop in bash script only run once -
the script goal simple.
i have many directory contains captured traffic files. want run command each directory. came script. don't know why script run first match.
#!/bin/bash # collect throughput group of directory containing capture files # group of directory can specify pattern # usage: ./collectthroughputlist [regex] # [regex] name pattern of group of directory dir in $( ls -d $1 ); if test -d "$dir"; echo collecting throughputs directory: "$dir" ( sh collectthroughput.sh $dir > $dir.txt ) fi done echo done\! i try with:
for dir in $1; or
for dir in `ls -d $1`; or
for dir in $( ls -d "$1" ); or
for dir in $( ls -d $1 ); but result same. loop runs 1 time.
finally found 1 , did tricks work. however, know why first script doesn't work.
find *delay50ms* -type d -exec bash -c "cd '{}' && echo enter '{}' && ../collectthroughput.sh ../'{}' > ../'{}'.txt" \; "*delay*" directory pattern name want run command with. pointing out issues.
problem
most problem encountering due fact trying use kind of pattern * argument script.
running like:
my_script * what's happening here is, shell expand * prior calling script. after word splitting has been performed $1 in script reference first entry returned ls.
example
given following directory layout:
directory_a directory_b directory_c calling my_script * result in:
my_script directory_a directory_b directory_c being called loop iterating on $(ls -d directory_a) in fact nothing else directory_a alone.
solution
to have program run $1=* have escape * prior calling script.
try running:
my_script \* to see intended then. way $1 in script contain * instead of directory_a way wanted script work.
Comments
Post a Comment