I wrote some code which searches parts of a split-archive backup (it's an Android backup, I used flashfire to backup) and rejoins them. As you can easily see, I've achieved this by if statements and the maximal number of archive parts is hardcoded (although NOT limited to 4 parts).As I'm very new to programming (if you like to name it by that) I'm quite     unsure how this could be done better, especially the part where the archive parts are searched and joined. How can I let the script search, with like a wildcard or something, the backup parts by itself without having to write an if statement for every single part there is?PRINT_LINE3echo To create a DB make sure that you have:echoecho [REQUIRED] system.tlz4 and all system.*.tlz4 echo [OPTIONAL] data.tlz4 and all data.*.tlz4    echo in $BASE_DIRecholocal READY=0while [[ $READY -eq 0 ]]; do    echo    echo Please fill a path for your system.tlz4 file    echo Potential candidates:    echo =-=-=-=-=-=-=-=-=    find ./base_drops -type f -iname system.tlz4    echo =-=-=-=-=-=-=-=-=    read -p system.tlz4:  SYSTEM_BAK    echo    echo Please fill a path for your data.tlz4 file. Leave empty if none.    echo Potential candidates:    echo =-=-=-=-=-=-=-=-=    find ./base_drops -type f -iname data.tlz4    echo =-=-=-=-=-=-=-=-=    read -p data.tlz4:  DATA_BAK    if [[ -f $SYSTEM_BAK ]] && ([[ -z $DATA_BAK || -f $DATA_BAK ]]); then        READY=1    else        echo Some of your files do not exist        PRESS_ENTER    fidone# creates db dir plus subdirs if neededPRINT_LINE3read -p Name your database:  NAMEPRINT_LINE1export ACTIVE_DB=./DB_$NAMEexport LIST_DIR=$ACTIVE_DB/listsexport LOGS_DIR=$ACTIVE_DB/logsexport ROM_DIR=$ACTIVE_DB/romexport SYS_DIR=$ACTIVE_DB/rom/systemif [[ ! -z $DATA_BAK ]] ; then    export DATA_DIR=$ACTIVE_DB/rom/datafiecho Creating $ACTIVE_DB, please wait...mkdir -p $ACTIVE_DBmkdir -p $LIST_DIRmkdir -p $LOGS_DIRmkdir -p $SYS_DIRif [[ ! -z $DATA_BAK ]] ; then      mkdir -p $DATA_DIRfi# SYSTEM# find backup partsecho Merging: echo -n System partition if [[ -f ./base_drops/system.0004.tlz4 ]] ; then    export SYSTEM_BAK4=./base_drops/system.0004.tlz4    export SYSTEM_BAK3=./base_drops/system.0003.tlz4    export SYSTEM_BAK2=./base_drops/system.0002.tlz4     cat $SYSTEM_BAK $SYSTEM_BAK2 $SYSTEM_BAK3 $SYSTEM_BAK4 > $ACTIVE_DB/rom/system/system.tar.lz4    echo (4 parts) -> $SYSTEM_BAK $SYSTEM_BAK2 $SYSTEM_BAK3 $SYSTEM_BAK4    else    if [[ -f ./base_drops/system.0003.tlz4 ]] ; then        export SYSTEM_BAK3=./base_drops/system.0003.tlz4        export SYSTEM_BAK2=./base_drops/system.0002.tlz4          cat $SYSTEM_BAK $SYSTEM_BAK2 $SYSTEM_BAK3 > $ACTIVE_DB/rom/system/system.tar.lz4        echo (3 parts) -> $SYSTEM_BAK $SYSTEM_BAK2 $SYSTEM_BAK3        else        if [[ -f ./base_drops/system.0002.tlz4 ]] ; then            export SYSTEM_BAK2=./base_drops/system.0002.tlz4              cat $SYSTEM_BAK $SYSTEM_BAK2 > $ACTIVE_DB/rom/system/system.tar.lz4            echo (2 parts) -> $SYSTEM_BAK $SYSTEM_BAK2            fi    fifi    # /DATA-Partition backupif [[ ! -z $DATA_BAK ]] ; then    echo -n  Data partition     if [[ -f ./base_drops/data.0004.tlz4 ]] ; then       # check for backup split-archive parts        export DATA_BAK4=./base_drops/data.0004.tlz4        export DATA_BAK3=./base_drops/data.0003.tlz4        export DATA_BAK2=./base_drops/data.0002.tlz4        cat $DATA_BAK $DATA_BAK2 $DATA_BAK3 $DATA_BAK4 > $ACTIVE_DB/rom/data/data.tar.lz4        # join into one archive        echo (4 parts) -> $DATA_BAK $DATA_BAK2 $DATA_BAK3 $DATA_BAK4        else         if [[ -f ./base_drops/data.0003.tlz4 ]] ; then            export DATA_BAK3=./base_drops/data.0003.tlz4            export DATA_BAK2=./base_drops/data.0002.tlz4            cat $DATA_BAK $DATA_BAK2 $DATA_BAK3 > $ACTIVE_DB/rom/data/data.tar.lz4            echo (3 parts) -> $DATA_BAK $DATA_BAK2 $DATA_BAK3            else            if [[ -f ./base_drops/data.0002.tlz4 ]] ; then                export DATA_BAK2=./base_drops/data.0002.tlz4                cat $DATA_BAK $DATA_BAK2 > $ACTIVE_DB/rom/data/data.tar.lz4                echo (2 parts) -> $DATA_BAK $DATA_BAK2                fi        fi    fifi
Search and merge split-archive backup parts
beginner;bash;osx
You could eliminate the tedious if-else chains using wildcard expansion:cat $SYSTEM_BAK ./base_drops/system.000[234].tlz4 > $ACTIVE_DB/rom/system/system.tar.lz4Or possibly even the simpler but less strict pattern:cat $SYSTEM_BAK ./base_drops/system.*.tlz4 > $ACTIVE_DB/rom/system/system.tar.lz4If you want to print the count of the number of parts, then you can store the filenames in an array:parts=($SYSTEM_BAK ./base_drops/system.*.tlz4)And then print the message like this:echo (${#parts[@]} parts) -> ${parts[@]}    You can do similarly for the data files.Btw, it seems a bit strange to prompt the user for SYSTEM_BAK, but for the parts use a fixed path. I'm wondering if the program really works as intended.If you drop the prompting (as you mentioned in a comment), note that you cannot simplify the array creation to this:parts=(./base_drops/system*.tlz4)This won't order the system.tlz4 and system.XXXX.tlz4 files the way you want, as it will put system.tlz4 at the end. So you need to write as:parts=(./base_drops/system.tlz4 ./base_drops/system.*.tlz4)