简体   繁体   中英

Weird behaviour of cp command

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

Change the shebang to #!/bin/bash -x and look at the output and make sure that everything is expanded properly...

Read more about bash debugging here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM