samedi 5 septembre 2020

Sequence of bash commands fails when enclosed in if ... fi - Why? And how to write it in POSIX style?

The following sequence of commands works fine

EHRbase_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)
echo ${EHRbase_VERSION}
java -jar application/target/application-${EHRbase_VERSION}.jar --cache.enabled=false > log &
grep -m 1 "Started EhrBase in" <(tail -f log)

But when I try to run them conditionally they don't work as I want

if [ "${MY_ENV}" != "FOO" ]; then
  EHRbase_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)
  echo ${EHRbase_VERSION}
  java -jar application/target/application-${EHRbase_VERSION}.jar --cache.enabled=false > log &
  grep -m 1 "Started EhrBase in" <(tail -f log)
fi

The result is

0.13.0
[1] 17584

# from here it seems to hang and I have to exit w/ CTRL+C

What is going wrong? How to write it correctly in BASH? How to write it in POSIX?

Aucun commentaire:

Enregistrer un commentaire