Issue
I am writing a script that allows users to provide additional docker build args using a config file.
BUILD_ARGS=
source ./userconfig.sh
docker build $BUILD_ARGS ...
In userconfig.sh,
USERID=$(id -u)
BUILD_ARGS="--build-arg=\"USERID=$USERID\" --build-arg\"SECONDARG=somethingelse\""
I see that the args are being single quoted when executed
docker build '--build-arg="USERID=1000"' '--build-arg="SECONDARG=somethingelse"' ...
I have tried using arrays instead of string.
BUILD_ARGS=()
BUILD_ARGS=( --build-arg=\"USERID=$USERID\" --build-arg\"SECONDARG=somethingelse\" )
docker build "${BUILD_ARGS[@]}" ...
I get the same error.
How can i fix this?
Solution
Use an array. Do not escape specially in an array, use it normally like you would on command line.
BUILD_ARGS=( --build-arg="USERID=$USERID" --build-arg"SECONDARG=somethingelse" )
docker build "${BUILD_ARGS[@]}" ...
Answered By - KamilCuk Answer Checked By - Candace Johnson (WPSolving Volunteer)