Home > Mobile >  Add mutiple file paths into one in shell script
Add mutiple file paths into one in shell script

Time:06-30

I have not coded in bash or made shell scripts before. The following code is working for me now in a shell script. ashlar is a python library which does multiple image stitching and registration. My question is how can I write only one variable instead of $c1 $c3 $c5 $c7 in the last line. I have tried using or cat but it didn't work.

for i in 1 3 5 7
do
 export ROOT_DIR=a/b/c/abcd_"$i"_123/
 export FILENAME_HEADER=a_b_c_40X_
 export WIDTH=5
 export HEIGHT=15
 export PIXEL_SIZE=0.1507
 export OVERLAP=0.1
 export LAYOUT=snake
 export DIRECTION=vertical
 export MAX_SHIFT=30
 export SIGMA=2
 export ALIGN_CHANNEL=4
 export OUTPUT_DIR=a/b/c/sample.ome.tiff

 export c"$i"="fileseries|""$ROOT_DIR""|pattern=""$FILENAME_HEADER"""$i"_F{series}.ome.tiff|width=""$WIDTH""|height=""$HEIGHT""|pixel_size=""$PIXEL_SIZE""|overlap=""$OVERLAP""|layout=""$LAYOUT""|direction=""$DIRECTION"
done

ashlar $c1 $c3 $c5 $c7 --flip-y --pyramid --maximum-shift $MAX_SHIFT --filter-sigma $SIGMA --align-channel $ALIGN_CHANNEL -o $OUTPUT_DIR

CodePudding user response:

Don't use numbered variables, use an array:

c=()
for i in 1 3 5 7
do
    export ROOT_DIR="a/b/c/abcd_${i}_123/"
    ...
    c =( "fileseries|${ROOT_DIR}|pattern=${FILENAME_HEADER}${i}_F{series}.ome.tiff|width=${WIDTH}|height=${HEIGHT}|pixel_size=${PIXEL_SIZE}|overlap=${OVERLAP}|layout=${LAYOUT}|direction=${DIRECTION}" )
    #^^^ .............................................................................................................................................................................................. ^
done

Then

ashlar "${c[@]}" --flip-y --pyramid --maximum-shift "$MAX_SHIFT" --filter-sigma "$SIGMA" --align-channel "$ALIGN_CHANNEL" -o "$OUTPUT_DIR"
# .....^^^^^^^^^

Some notes:

  • Related