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 Answer 1

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[@]}"
8
  • 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. Commented Jan 3, 2018 at 13:05
  • The configure script is a GNU autotools like one, for example from GNU Octave, where I first recognized this problem. Commented Jan 3, 2018 at 13:18
  • @M.K.akaGrisu, Can you try the last example in my answer? I think this is what you need.
    – jesse_b
    Commented Jan 3, 2018 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.
    – phemmer
    Commented Jan 3, 2018 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
    Commented Jan 3, 2018 at 14:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .