1

Laravel Sail should support multiple docker-compose files by configuring them in a dotenv file (.env).

The line in my .env file...

SAIL_FILES='docker-compose.yml:docker-compose-arm.yml'

The part of Sail that handles multiple sail files (I can't/shouldn't edit this)

if [ -n "$SAIL_FILES" ]; then
    # Convert SAIL_FILES to an array...
    SAIL_FILES=("${SAIL_FILES//:/ }")

    for FILE in "${SAIL_FILES[@]}"; do
        if [ -f "$FILE" ]; then
            DOCKER_COMPOSE+=(-f "$FILE")
        else
            echo "${BOLD}Unable to find Docker Compose file: '${FILE}'${NC}" >&2

            exit 1
        fi
    done
fi

I've tried a few different delimiters (comma, spaces, .etc). It seems simple but I can't get it to work. I can't understand how SAIL_FILES=("${SAIL_FILES//:/ }") performs the array conversion (I'm new to Bash).

I've recreated the issue here which should simply echo each filename on a new line.

This doesn't seem to be documented anywhere on Laravel.

Thanks.

1 Answer 1

1

Double quoting prevents word-splitting. If you want word-splitting to happen, don't quote:

SAIL_FILES=(${SAIL_FILES//:/ })

You can also use $IFS to split the string without substitution:

IFS=: SAIL_FILES=($SAIL_FILES)
7
  • That works. I want to avoid editing vendor code. So is this a Laravel Sail issue and my delimiter is fine?
    – Mike
    Commented Jan 6, 2023 at 12:58
  • Does it run in bash or some other shell?
    – choroba
    Commented Jan 6, 2023 at 16:45
  • I'm currently on a mac so zsh. ps -p $$ outputs... ` PID TTY TIME CMD 15820 ttys005 0:03.64 /bin/zsh --login -i `
    – Mike
    Commented Jan 9, 2023 at 14:20
  • @mike How do you run the script that contains the code you posted? What shebang line does it start with?
    – choroba
    Commented Jan 9, 2023 at 14:30
  • #!/usr/bin/env bash
    – Mike
    Commented Jan 9, 2023 at 16:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.