SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes

CC=`which gcc`
CONFIGopt=' --prefix=/ --exec-prefix=/usr --libexecdir=/usr/lib/libexec --includedir=/usr/include --with-random=/dev/random'  
SSLopts=' --with-openssl=/usr/local/openssl-1.0.0j-pkcs11'
BUILD64=' -m64 -mcpu=v9'

./configure CC="\"${CC} ${BUILD64}"\" ${CONFIGopt} ${SSLopts}

When i run the sh -x script.sh i get the following output.

+sh ./configure CC="gcc -m64 -mcpu=v9" --prefix=/ --exec-prefix=/usr \
--libexecdir=/usr/lib/libexec --includedir=/usr/include --with-random=/dev/random --with-openssl=/usr/local/openssl-1.0.0j-pkcs11
checking build system type... sparc-sun-solaris2.9
checking host system type... sparc-sun-solaris2.9
checking for gcc... "gcc -m64 -mcpu=v9"
checking whether the C compiler works... no           <-------- FAILURE
configure: error: in `/bind-9.9.1-P2':
configure: error: C compiler cannot create executables
See 'config.log' for more details

config.log just has: configure:4078: "/usr/local/bin/gcc: No such file or directory.

BUT if I copy that command line and paste it to the prompt everything works.
:wall:
if i put that expanded command line into the script, it works
:wall::wall:

./configure CC="\"${CC} ${BUILD64}\"" ${CONFIGopt} ${SSLopts}

It looks like you're trying to cram flags into CC? Those belong in ${CFLAGS} instead.

rdrtx1:
Uhm, it looks like you just changed which set of quotes were passed to the shell, i don't see anything else. Didn't make any difference though.

Corona688:
Wouldn't the ${CFLAGS} just be a different variable NAME, or is ${CFLAGS} actually handled differently.

The CC variable specifies the C compiler executable to use and nothing else. You need to alter the CFLAGS variable to alter the compile flags, you can't cram them in there.

1 Like

Corona i'm confused that the command works fine when entered at the command line.

./configure CC="gcc -m64 -mcpu=v9" ...

CRAPPPPPPP. i just realized i was using CC in the command line to pass and not letting the env variable to be executed. Thank you Corona you made me thing about the way CC and CFLAGS were set.

CC=`which gcc`; export CC
CFLAGS="-m64 -mcpu=v9"; export CFLAGS
1 Like

Is everything working, then?

it got passed where it did before so that part seems ok. I'm erroring in the config section due to OpenSSL library now i believe. I get "linking with OpenSSL works: no".

must be a 64 bit library or maybe OpenSSL wasn't built as 64bit.

Keep in mind that having openssh installed isn't the same as being able to compile things that use openssh libraries.

You might need to install openssh-dev or something like that to get the headers and library files the compiler needs.