0

I have the following: test.ini

BUILD_ARGS='--build-arg user="test user" --build-arg pass=testPass'

test.sh

#!/bin/bash
set -x
source test.ini
docker build -t test:test ${BUILD_ARGS} .

Output of test.sh

+ source test.ini
++ BUILD_ARGS='--build-arg smb_user="test user" --build-arg smb_pass=testPass '
+ docker build -t test:test --build-arg 'user="test' 'user"' --build-arg pass=testPass .

Why are extra single quotes being added in between "test" and "user"? I would expect the command to be executed as:

docker build -t test:test --build-arg user="test user" --build-arg pass=testPass .
David C. Rankin
  • 81,885
  • 6
  • 58
  • 85
nxf5025
  • 183
  • 1
  • 1
  • 7
  • 2
    This is normal, expected behavior. See [BashFAQ #50](http://mywiki.wooledge.org/BashFAQ/050), and don't try to use strings to store lists; only *arrays* are appropriate for that purpose. – Charles Duffy Aug 02 '19 at 22:46

1 Answers1

1

Arguments needs to be constructed as an array:

BUILD_ARGS=(--build-arg user="test user" --build-arg pass="testPass")

docker build -t test:test "${BUILD_ARGS[@]}"
Léa Gris
  • 17,497
  • 4
  • 32
  • 41