3

I am trying to configure some software packages with a script thereby I got the following problem. Assume that the environment variable PREFIX is set to the location where I plan to install the software. Inside my script I have

CONFOPTS="--enable-shared --with-blas=\"-L${PREFIX}/lib/ -lblas\" --with-lapack=\"-L${PREFIX}/lib -llapack\""
echo CONFOPTS=$CONFOPTS    

which prints

CONFOPTS=--enable-shared --with-blas="-L/scratch/test/lib/ -lblas" --with-lapack="-L/scratch/test/lib -llapack"

If a want to run configure afterwards in the script

set -x
./configure --prefix=${PREFIX} ${CONFOPTS}
set +x

it gets expanded to

 ./configure --prefix=/scratch/test --enable-shared '--with-blas="-L/scratch/test/lib/' '-lblas"' '--with-lapack="-L/scratch/test/lib' '-llapack"'

which is rubbish and misinterpreted by the configure script and the shell. The correct one would be

./configure --prefix=/scratch/test --enable-shared --with-blas="-L/scratch/test/lib/ -lblas" --with-lapack="-L/scratch/test/lib -llapack"

How can I change the behavior such that I obtain a proper command line in the configure call?

1

Put your options into an array instead, then you can quote it:

declare -a CONFOPTS
CONFOPTS=(
    '--enable-shared'
    "--with-blas=-L${PREFIX}/lib/ -lblas"
    "--with-lapack=-L${PREFIX}/lib -llapack"
)


./configure --prefix="${PREFIX}" "${CONFOPTS[@]}"

I'm not sure if I have separated your options correctly, please let me know if you need help making adjustments.


If you really need to maintain those double quotes and pass them to configure, try this:

declare -a CONFOPTS
CONFOPTS=(
    '--enable-shared'
    '--with-blas="-L${PREFIX}/lib/ -lblas"'
    '--with-lapack="-L${PREFIX}/lib -llapack"'
)


./configure --prefix="${PREFIX}" "${CONFOPTS[@]}"

Or even this?:

declare -a CONFOPTS
CONFOPTS=(
    '--enable-shared'
    "--with-blas=\"-L${PREFIX}/lib/ -lblas\""
    "--with-lapack=\"-L${PREFIX}/lib -llapack\""
)


./configure --prefix="${PREFIX}" "${CONFOPTS[@]}"
  • In general this would work but many parts of the code require CONFOPTS to be a string rather than being an array. So this solution will not work easily for my purpose. – M.K. aka Grisu Jan 3 '18 at 13:05
  • The configure script is a GNU autotools like one, for example from GNU Octave, where I first recognized this problem. – M.K. aka Grisu Jan 3 '18 at 13:18
  • @M.K.akaGrisu, Can you try the last example in my answer? I think this is what you need. – Jesse_b Jan 3 '18 at 13:34
  • The last 2 solutions (putting double quotes inside the arg) wont work properly as the shell is just going to pass literal quotes to ./configure. The first option is the right way. – Patrick Jan 3 '18 at 13:38
  • 2
    @M.K.akaGrisu, note that the single quotes around the arguments in the output of set -x are there just to make the output unambiguous. They also make the output usable as input to the shell, so you need to use the shell's quoting rules to interpret them. – ilkkachu Jan 3 '18 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.