I'm about to launch and perform an action in every subdir on one parent directory using this:
for i in ./*/*R1.fastq;
do
if [ -d "${i}" ]; then
echo "${i}"
python2.7 demultadapt.py -f $i -p Demul-01-R1 FILE_ADAPT
fi
done
but it never succeed. Please help!
CodePudding user response:
Please properly explain what you are trying to achieve.
Do you want to act on all directories that contain *R1.fastq files?
for f in ./*/*R1.fastq; do
d=$(dirname "$f")
if [ -d "$d" ]; then
echo "$d"
python2.7 demultadapt.py -f "$d" -p Demul-01-R1 FILE_ADAPT
fi
done
CodePudding user response:
Why not do this with find
?
find <parent> -type d -print -exec python2.7 demultadapt.py -f {} -p Demul-01-R1 FILE_ADAPT \;
Where
<parent>
is your starting / parent directory-type d
only return directories-print
print out every hit-exec <command> \;
in each directory execute your command. Note that{}
will be replaced by the current hit, and the trailing\;
is required.