1

Can anyone help me get the following bash script working with double quotes (see difference between ${PATH_TO_RELEASES} with and without double quotes)?

function run() {
  OUTPUT=$(ssh -T "${USER}@${HOST}" eval "$@")

  EXIT_CODE=$?
  if [ "${EXIT_CODE}" -ne 0 ]; then
    exit 1;
  fi

  echo "${OUTPUT}"
}

This works:

run "
  COUNT_RELEASES=\$(find ${PATH_TO_RELEASES}/releases/* -maxdepth 0 -type d | wc -l)
  echo \${COUNT_RELEASES}
"

This doesn't work (see double quoting/escaping). It throws the following error messages: find: /path/to/releases/releases/*: No such file or directory

 run "
  COUNT_RELEASES=\$(find \"${PATH_TO_RELEASES}/releases/*\" -maxdepth 0 -type d | wc -l)
  echo \${COUNT_RELEASES}
"
Twoez
  • 540
  • 1
  • 5
  • 17

0 Answers0