'Bash - How to add item into array with special characters (DIRECTORY SEPERATOR) - division by 0 (error token is)

I am creating a bash script to copy a set of source files to different destination directories. I want to automate this process more, especially for tiny repeated changes, and want to cut out the compilation wait time of Magento 2 (while also using a single set of files that are not in a git repo).

Question

How do I correctly add to bash Arrays, specifically paths with slashes?

Context

Magento 2 uses app/design/frontend/Vendor/Theme/* for overridden theme files which then compiles into pub/static/frontend/{language}/*. This is usually sufficient if you have a single file and then compile to a single website.

This process becomes more cumbersome if you just want to quickly upload a small fix/update to a Javascript file; just to recompile again (waiting ~3+ minutes); so while testing it may be faster just to replace the compiled file on the different folder locations (app/design/frontend and pub/static/frontend/)

  • There are multiple sites (eg. site1, site2)
  • There are multiple languages (eg. en_GB, en_US)
  • There are multiple themes (eg. Vendor1/Theme1, Vendor2/Theme2)

Error

line 11: app/design/frontend/Vendor/Theme_Name: division by 0 (error token is "design/frontend/Vendor/Theme_Name")

--- line 11 code: ---
COPY_TO_FOLDER_LOCATIONS=("${TEMP_COPY_FOLDER_LOCATIONS[@]}" "${TEMP_COPY_FOLDER_LOCATIONS[indexLocation]}")

I also tried:

COPY_TO_FOLDER_LOCATIONS+=("${TEMP_COPY_FOLDER_LOCATIONS[indexLocation]}" )

From the error it is clear that the bash interprets the code where I want to add an item INTO the array as arithmetic (division by 0) (the error token shows path without app),

Bash script

ROOT_FOLDER="$PWD"
# Copy to these locations
THEME_NAME="Vendor/Theme_Name"
declare -a LANGUAGES=("en_GB" "en_US")

declare -a COPY_TO_ROOT_LOCATIONS=("/var/www/html/site1" "/var/www/html/site2")
declare -a TEMP_COPY_TO_FOLDER_LOCATIONS=("app/design/frontend/$THEME_NAME" "pub/static/frontend/{language}/$THEME_NAME")
declare -a COPY_TO_FOLDER_LOCATIONS=()

for indexLocation in "${TEMP_COPY_TO_FOLDER_LOCATIONS}"; do
#### Once I get this sorted, here I will use getThemeLanguagePath() to get the path to add to
    COPY_TO_FOLDER_LOCATIONS=("${TEMP_COPY_FOLDER_LOCATIONS[@]}" "${TEMP_COPY_FOLDER_LOCATIONS[indexLocation]}")
done

for indexLocation in "${COPY_TO_FOLDER_LOCATIONS}"; do
    echo "$COPY_TO_FOLDER_LOCATIONS}"
    tText=getThemeLanguagePath "ABC" "$COPY_TO_FOLDER_LOCATIONS"
    echo "LOCATION : $tText"
done

readarray -d '' MOVE_FILES < <(find $ROOT_FOLDER -type f -name "*.move" -print0)

echo "${#MOVE_FILES[@]}"

function getThemeLanguagePath(){
    local language="$1"
    local path="$2"
    echo "$2/$1"
}

for indexLocation in "${!COPY_TO_ROOT_LOCATIONS[@]}"; do
    for indexFile in "${!MOVE_FILES[@]}"; do
        file="${MOVE_FILES[indexFile]}"
        source="$file"
        destination="$(basename -- $file)"
        #destination=$("${file##*/}")
        echo "$source"
        echo "$destination"
    done
done

Objective

  • I need to test changes across all themes quicker.
  • These things are core Javascript/CSS that needs to work on different themes, and can't be solved with creating a custom module

This is a rough draft which will be improved when I have solved the issues. I want to automate the process and create dynamic paths to copy the files from the source (.move files) into different paths

  • There are multiple sites (eg. site1, site2)
  • There are multiple languages (eg. en_GB, en_US)
  • There are multiple themes (eg. Vendor1/Theme1, Vendor2/Theme2)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source