开发者

Weird behaviour of cp command

开发者 https://www.devze.com 2023-03-16 23:47 出处:网络
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.

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 createI开发者_运维技巧nstance 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

0

精彩评论

暂无评论...
验证码 换一张
取 消