天哪,我尝试了 MAN 页面,以及这里的几个帖子。我想我只是愚蠢,因为我不明白。
我有一个包含 {VERSION} 和 {DISTRO} 的 javascript 文件,其中的变量字符串值应该像这样替换。
var MyObject = {
/**
* @property {string} VERSION Holds the current version of the framework
*/
VERSION: '{VERSION}',
/**
* @property {string} DISTRO Holds the distrobution tag of the framework
*/
DISTRO: '{DISTRO}'
};
这个命令为我的 shell 运行。无论我做什么,它都不起作用或我得到错误。
VERSION="0.9.0"
DISTRO="Developer"
OUT_CAT=$OUT_CAT_DEBUG
${OUT_CAT} | sed -i "s/{VERSION}/\$VERSION/" -e "s/{DISTRO}/\$DISTRO/" ${OUT_CAT}
#sed -i "s/{VERSION}/$VERSION/" -e "s/{DISTRO}/$DISTRO/" ${OUT_CAT}
那么我在哪方面是迟到的呢?似乎它应该非常简单和直接。
[编辑] 这是脚本的简化版本,因此您可以知道我在做什么以及变量来自哪里。
#!/bin/bash
VERSION="0.9.0"
DEV_DIR=../lib
DIST_DIR=../dist
WEB_DIR=/d/Android_Dev/GitHUB/WEB/h5c3/dist
OUT_CAT_DEBUG=h5c3.debug.cat
OUT_MIN_DEBUG=h5c3.debug.min
OUT_ZIP_DEBUG=$DIST_DIR/h5c3.debug.gz
OUT_CAT_RELEASE=$DIST_DIR/h5c3.release.cat
OUT_MIN_RELEASE=h5c3.release.min
OUT_ZIP_RELEASE=$DIST_DIR/h5c3.release.gz
echo Building Version "$1"...
if [ "$1" == debug ]; then
DISTRO="Developer"
OUT_CAT=$OUT_CAT_DEBUG
OUT_MIN=$OUT_MIN_DEBUG
OUT_ZIP=$OUT_ZIP_DEBUG
# empty it out
> ${OUT_CAT}
cat $DEV_DIR/packed.js >> ${OUT_CAT}
#Development support
cat $DEV_DIR/h5c3_debug.js >> ${OUT_CAT}
elif [ "$1" == release ]; then
DISTRO="Production"
OUT_CAT=$OUT_CAT_RELEASE
OUT_MIN=$OUT_MIN_RELEASE
OUT_ZIP=$OUT_ZIP_RELEASE
# empty it out
> ${OUT_CAT}
cat $DEV_DIR/packed.js >> ${OUT_CAT}
cat $DEV_DIR/h5c3_release.js >> ${OUT_CAT}
else
#publish.sh debug
#publish.sh release
exit 2
fi
#Build Game Core
cat $DEV_DIR/core/stacktrace.js >> ${OUT_CAT}
#Build Externals
cat $DEV_DIR/ext/base64.js >> ${OUT_CAT}
#Build Engine
cat $DEV_DIR/engine/boot.js >> ${OUT_CAT}
#Build Internal Components
cat $DEV_DIR/components/component.js >> ${OUT_CAT}
#Build Systems
cat $DEV_DIR/systems/system.js >> ${OUT_CAT}
#Build Framework
cat $DEV_DIR/framework/page.js >> ${OUT_CAT}
#Build Web App
cat $DEV_DIR/webapp/game.js >> ${OUT_CAT}
if [ "$1" == debug ]; then
#Development support
cat $DEV_DIR/debugger/profiler.js >> ${OUT_CAT}
cat $DEV_DIR/debugger/console.js >> ${OUT_CAT}
cat $DEV_DIR/debugger/debug.js >> ${OUT_CAT}
cat $DEV_DIR/debugger/developer.js >> ${OUT_CAT}
fi
if [ "$1" == release ]; then
echo Removing any debug calls from ${OUT_CAT}
sed -i '/this.debug/d' ${OUT_CAT}
fi
echo "Inserting distribution & version in ${OUT_CAT}"
${OUT_CAT} | sed -i "s/{VERSION}/\$VERSION/" -e "s/{DISTRO}/\$DISTRO/" ${OUT_CAT}
echo Minimizing...[${OUT_CAT} to ${OUT_MIN}]
> ${OUT_MIN}
java -jar yuicompressor-2.4.7.jar ${OUT_CAT} -o ${OUT_MIN}
#echo Compressing...[${OUT_MIN} to ${OUT_ZIP}]
#gzip --best --force ${OUT_MIN}
echo Copying to WEB Folder...
cp --update ${OUT_MIN} ${WEB_DIR}
echo Complete.
exit