How to parse a string with multiple characters to split on-Bash Scripting

IFS is not a single, multicharcter delimiter; instead, it is a collection of single-character delimiters. You can use a regular expression to break apart two fields separated by an arbitrary delimiter.

regex='(.*) >> (.*)'
while IFS= read -r line dest
do 
    [[ $line =~ $regex ]] || continue
    src=${BASH_REMATCH[1]}
    dest=${BASH_REMATCH[2]}

    if [[ -n $src ]]; then
        SOURCEFILES+=("$src")
    fi
    if [[ -n $dest ]]; then  
        DESTINATIONFILES+=("$dest")
    fi  
done < "$TransferDescriptor"

Leave a Comment