lova
lova

Reputation: 879

Environment variable does not work inside command

I'm stuck for houres on this strange issue. I have a bashscript which is executing the following:

TEST="12.x.x.x"

echo ${TEST} gave me 12.x.x.x

So now I want to use this env var in my command:

oadm ca create-server-cert --signer-cert=ca.crt \
    --signer-key=ca.key --signer-serial=ca.serial.txt \
    --hostnames='docker-registry.default.svc.cluster.local,$TEST' \
    --cert=registry.crt --key=registry.key

An echo of this command shows the content of $TEST in it. But the command fails (it did not create the crt and key for my IP). But it works when I'm just executing:

oadm ca create-server-cert --signer-cert=ca.crt \
    --signer-key=ca.key --signer-serial=ca.serial.txt \
    --hostnames='docker-registry.default.svc.cluster.local,12.x.x.x' \
    --cert=registry.crt --key=registry.key

What could be the issue? An echo of $TEST gave always my IP. Before and after the command.

Upvotes: 0

Views: 62

Answers (2)

mauro
mauro

Reputation: 5950

Single quotes prevent variable expansion. Try with double quotes:

oadm ca create-server-cert --signer-cert=ca.crt \
    --signer-key=ca.key --signer-serial=ca.serial.txt \
    --hostnames="docker-registry.default.svc.cluster.local,${TEST}" \
    --cert=registry.crt --key=registry.key

Upvotes: 2

Vlad Cenan
Vlad Cenan

Reputation: 172

The variable is not valid between single quotes'', you should use double quotes "" , like this:

--hostnames="docker-registry.default.svc.cluster.local,$TEST"

Upvotes: 0

Related Questions