比较来自世界各地的卖家的域名和 IT 服务价格

执行脚本时出现的坏字符 bash

我有一个脚本 bash, 它添加了一个强调一些行的符号,这导致了他的失败,我找不到这些角色到达那里的地方和地点。

以下是输出的一些示例:


mv: cannot move â/tmp/myapp.zipâ to â/opt/myserver/myapp/deploys/myapp.1.2.21.zipâ: No such file or directory
ln: failed to create symbolic link â/opt/myserver/myapp/deploys/myapp_beta.zipâ: No such file or directory
cp: cannot stat â/opt/myserver/myapp/deploys/myapp_beta.zipâ: No such file or directory


无效的符号是符号

â

.

脚本如下:


#!/bin/bash

BRANCH=$1

SVN_LOC="[url=https://svn/svn/myserver/"]https://svn/svn/myserver/"[/url]

MYAPP_REPO="myapp.git"
COREJS_REPO="core-js.git"
SPARTAN_REPO="core-spartan.git"

MYAPP_LOCATION="myapp/"
COREJS_LOCATION="corejs/"
SPARTAN_LOCATION="spartan/"

DEPLOY_LOCATION="/tmp/deploy/"
CLEANUP="${DEPLOY_LOCATION}*"

DEPLOY_STORE="/opt/myserver/myapp/deploys/"

DEPLOY_TIME=$/date +%s/

failed //
{
rm -rf $CLEANUP
exit 1
}

mkdir -p $DEPLOY_LOCATION

echo "Retrieving Code from Git Branch ${BRANCH}"

echo "Retrieving myapp code"

mkdir -p "${DEPLOY_LOCATION}${MYAPP_LOCATION}"
pushd /opt/myserver/myapp/myapp
git archive $BRANCH | tar -x -C "${DEPLOY_LOCATION}${MYAPP_LOCATION}"
if [ $? -ne 0 ]
then
echo "Failed retrieving code from git ${MYAPP_REPO} repo";
failed
fi
popd

echo "Checking version numbers"
VERSION=$/php "${DEPLOY_LOCATION}${MYAPP_LOCATION}version.php" output/

DEPLOY_PACKAGE="${DEPLOY_STORE}myapp.${VERSION}.zip"

if [ -f $DEPLOY_PACKAGE ]
then
echo "A deploy with the same version number /${VERSION}/ already exists! Please increment version number or manually deal with existing ${DEPLOY_PACKAGE}";
failed
fi

echo "Retrieving corejs code"

mkdir -p "${DEPLOY_LOCATION}${COREJS_LOCATION}"
pushd /opt/myserver/myapp/core-js
git archive $BRANCH | tar -x -C "${DEPLOY_LOCATION}${COREJS_LOCATION}"
if [ $? -ne 0 ]
then
echo "Failed retrieving code from git ${COREJS_REPO} repo";
failed
fi
popd

echo "Retrieving spartan code"

mkdir -p "${DEPLOY_LOCATION}${SPARTAN_LOCATION}"
pushd /opt/myserver/myapp/spartan
git archive $BRANCH | tar -x -C "${DEPLOY_LOCATION}${SPARTAN_LOCATION}"
if [ $? -ne 0 ]
then
echo "Failed retrieving code from git ${SPARTAN_REPO} repo";
failed
fi
popd

echo "Minifying js and css"

pushd "${DEPLOY_LOCATION}${MYAPP_LOCATION}Server/Deploy/"
php MinifyLyroke.php --deploytime $DEPLOY_TIME
popd

ASSETS_DEPLOY_PACKAGE="${DEPLOY_STORE}myappassets.${VERSION}.zip"
TEMP_ASSETS_ZIP_LOC="/tmp/myappassets.zip"
DEPLOY_ASSETS="${DEPLOY_LOCATION}myapp/Assets/"
ASSETS_DEPLOY_LOCATION="/tmp/assetsdeploy/"
DEPLOYED_ASSETS="${ASSETS_DEPLOY_LOCATION}myappassets_${DEPLOY_TIME}"

mkdir -p $ASSETS_DEPLOY_LOCATION

echo "Packaging assets deploy to ${ASSETS_DEPLOY_PACKAGE}"

mv $DEPLOY_ASSETS $DEPLOYED_ASSETS

pushd $ASSETS_DEPLOY_LOCATION
zip -r ${TEMP_ASSETS_ZIP_LOC} *
popd

mv ${TEMP_ASSETS_ZIP_LOC} ${ASSETS_DEPLOY_PACKAGE}
ln -sfn ${ASSETS_DEPLOY_PACKAGE} "${DEPLOY_STORE}myappassets_beta.zip"
cp "${DEPLOY_STORE}myappassets_beta.zip" "/opt/myserver/myapp/myapp/Server/Deploy/"

rm -rf $DEPLOYED_ASSETS
rm -rf $ASSETS_DEPLOY_LOCATION

echo "Packaging deploy to ${DEPLOY_PACKAGE}"

TEMP_ZIP_LOC="/tmp/myapp.zip"

pushd ${DEPLOY_LOCATION}
zip -r ${TEMP_ZIP_LOC} *
popd

mv "${TEMP_ZIP_LOC}" "${DEPLOY_PACKAGE}"
ln -sfn "${DEPLOY_PACKAGE}" "${DEPLOY_STORE}myapp_beta.zip"
cp "${DEPLOY_STORE}myapp_beta.zip" "/opt/myserver/myapp/myapp/Server/Deploy"

echo "Cleaning up"

rm -rf $CLEANUP


任何人都可以看到问题或建议我可以找到问题的方式吗?
已邀请:

君笑尘

赞同来自:

这些
â

符号 - 只是从你的迷惑聪明的智能报价 shell. 你的 shell, 可能是输出 UTF-8, 但是你的 terminal 在看书 ISO-8859-1. 注意
â

- 它是渲染编码的智能报价 UTF-8

在 ISO-8859-1 用两个字母后有两个未烧制的符号 "和". 最现代化的模拟器 terminal 完成了包含的可能性 UTF-8; 看看你是否可以启用它 /这将促进你的生活。/.

问题在于您的场景,而不是有趣的字符。

龙天

赞同来自:

例如,尝试在另一个文本编辑器中打开脚本 Notepad++, 并看看那里有任何特殊字符。

龙天

赞同来自:

在命令提示符中,输入两个命令。 一个或多个文件 / 您希望看到的董事不存在。


ls /tmp/myapp.zip
ls /opt/myserver/myapp/deploys

三叔

赞同来自:

答案接受解释了问题,谢谢 @nneonneo. 这就是你可以快速做的事情:

和/ 检查您的设置 locale 通过:


locale


B./ 在调用脚本或Bash脚本的顶部之前,请尝试:


export LANG=en_US.UTF-8
export LC_ALL=C

要回复问题请先登录注册