0

The following snippet of a bash script appears to function:

CF_Key=${CF_GLOBAL_API} CF_Email=${CF_EMAIL} ${ACME_PATH} --test --staging --issue --dns dns_cf -d ${DOMAIN_NAME}

However if I declare a variable and attempt to pass it to the script this does not:

ENV="CF_KEY=${CF_GLOBAL_API} CF_Email=${CF_EMAIL}"
${ENV} ${ACME_PATH} --test --staging --issue --dns dns_cf -d ${DOMAIN_NAME}

CF_Key=bsif987: command not found

I've even tried

"${ENV} ${ACME_PATH} --test --staging --issue --dns dns_cf -d ${DOMAIN_NAME}"

CF_Key=bsif987 [email protected] /root/.acme.sh/acme.sh --test --staging --issue --dns dns_cf -d test.gohilton.com: No such file or directory

Do I export the variables rather than pass them on command line?

KevDog
  • 51
  • 3
  • 1
    Related: https://unix.stackexchange.com/questions/444946 – Kusalananda Mar 20 '20 at 20:33
  • 1
    Re-think your approach, and why you want to pass variables inside other variables. That's broken. In the meanwhile, just using the `env` utility would probably work in this case: `env ${ENV} ${ACME_PATH} --test ...`. –  Mar 20 '20 at 21:08
  • 1
    Instead of that `ENV` variable, you could use a wrapper function: `cf_env(){ CF_FOO=foo CF_BAR=bar CF_BAZ=baz "$@"; }; ...; cf_env "$ACME_PATH" ...` –  Mar 20 '20 at 21:11
  • @mosvy I tried with an array approach but that seemed to produce a similar error to what I was posting. The env ${ENV} method however did seem to work. Thank you. – KevDog Mar 20 '20 at 22:05
  • 1
    bash does not do 2 rounds of evaluation by itself. You need `env` or `eval` to do what you hope to do. And many will say, if you need to use `eval` you need to find another way to do it. – glenn jackman Mar 20 '20 at 22:19
  • 3
    You could also simply `export` the variables first, then call "$ACME_PATH" without the preamble. – glenn jackman Mar 20 '20 at 22:21

0 Answers0