I have a strange problem with BASH script which I can't figure out. I don't know why this keeps happening. I don't post the whole script because of its length but only the important parts.
Information is in the script's comments.
Script
# replaces %ZONE% placeholder
# 2 params: path, zone in format z3, z4
zonePath() {
  value=`echo ${1} | sed "s/%ZONE%/${2}/"`
  echo $value
}
createInstance() {
  JBOSS_NAME="jboss"
  JBOSS_DIR="/home/jboss"
  # echo of OUTPUT_ZONE_DIR_TMP looks correctly like /home/jboss/z3
  OUTPUT_ZONE_DIR_TMP=`zonePath ${OUTPUT_ZONE_DIR} ${3}`
  if [[ ! -e ${OUTPUT_ZONE_DIR_TMP}/${JBOSS_NAME}/server/${2} ]]; then
    mkdir -p ${OUTPUT_ZONE_DIR_TMP}/${JBOSS_NAME}/server/${2}
    cp -r ${JBOSS_DIR}/${JBOSS_NAME}/server/default/* ${OUTPUT_ZONE_DIR_TMP}/${JBOSS_NAME}/server/${2}
  fi
  # BUT here I get an error of wrong directory because the path is
  # /home/jboss//jboss/server - the z3 string is missing there - WHY???
  cp -r `zonePath ${SOLUTION_APP_PATH} ${3}`/${1} ${OUTPUT_ZONE_DIR_TMP}/${JBOSS_NAME}/server/${2}/deploy
}
# in the script I call the createInstance function for example like this
createInstance "system-long-name" "sys" z3
createInstance "system2-long-name" "sys2" z4
 
    