I need two make a new bash array, not including elements which are in second one. And then use this array in while loop:

while [ -n "${ids_toproc[0]}" ] ; do

Here is a code a implemented:

all_ids=( /input/sub-* )
all_ids=( "${all_ids[@]#/input/sub-}" )
all_ids=( "${all_ids[@]%/}" )

exist_ids=( /output/fmriprep/sub-*.html )
exist_ids=( "${exist_ids[@]#/output/fmriprep/sub-}" )
exist_ids=( "${exist_ids[@]%/}" )
exist_ids=( "${exist_ids[@]%%.*}" ) # delete extention

ids_toproc=( `echo ${all_ids[@]} ${exist_ids[@]} | tr ' ' '\n' | sort | uniq -u` )

Is code is ok? is it right way to do compare?

1 Answer 1


This is a follow-up question to "shell script inside docker". Thanks for posting it as a separate issue!

What I would probably have done here, since the creation of your all_ids array needs to be slightly more complicated than just parsing the ID out from directory names, is to use a loop in which each ID is checked against the filenames the /output/fmriprep directory. If no output file is found for a given ID, then the ID is added to the all_ids list.

for dirname in /input/sub-*/; do
    id=${dirname#/input/sub-}    # remove "/input/sub-"
    id=${id%/}                   # remove trailing "/"

    if [ ! -e "/output/fmriprep/sub-$id.html" ]; then
        # no output file corresponding to this ID found,
        # add it to he list
        all_ids+=( "$id" )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .