bash - looping through pairs of input files -


this question has answer here:

i'm trying bash scripting batch execute existing package. input each execution requires 2 input files. can either use regular names or place each pair in own sub-directory make sure each pair stays together. i've got bits , pieces nothing loops on 2 files or enters sub-directory, something, moves , repeats on next sub-directory.

this perform want on single directory containing pair of files (each file pair named e.g. abc10f.txt , abc10r.txt):

#!/bin/bash # f=$(ls *f.txt)   echo "forward -> $f" i=$(ls *r.txt)   echo "reverse -> $i"; /path/to/package [options] $f $i; 

the following loop through each sub-directory in main directory executes when gets last 1 (note: testing helloworld.sh – thought if list each sub-dir , echo "hello world" after each i'd on way doing want; instead list of sub-directories followed single "hello world"):

#!/bin/bash # mycommand=/path/to/scripts/helloworld.sh  d in ./;   find * -maxdepth 1 -type d      cd $d     echo $pwd     exec "$mycommand" done 

a little putting together?

make helloworld.sh like:

#!/bin/bash  f in *f.txt;     r="${f/f.txt/r.txt}"     echo "  f: $f"     echo "  r: $r"     /path/to/package [options] "$f" "$r"; done 

and second sript:

#!/bin/bash # '*/' pattern matches of subdirectories in current directory d in */;     # doing actions in subshell ()     (cd "$d" && echo "$(pwd)" && bash /path/to/scripts/helloworld.sh) done 

Comments