我对BASH脚本有一个奇怪的问题,我无法弄清楚。我不知道为什么会这样。我不会发布整个脚本,因为它的长度只是重要的部分。
信息在脚本的评论中。
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