人品太差显示bash脚本执行起来(bad character showing up in bash

2019-10-30 04:08发布

我有越来越追加到一些字符串是导致它失败重音字符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

无效字符是A。

下面的脚本是:

#!/bin/bash

BRANCH=$1

SVN_LOC="https://svn/svn/myserver/"

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

任何人都可以看到可能的问题或建议的方式,我可以去寻找其中的问题是什么?

Answer 1:

这些â字符只是错位从shell印刷智能引号。 你的shell可能是输出UTF-8,但你的终端读取ISO-8859-1。 需要注意的是â是UTF-8编码的智能报价呈现'在ISO 8859,与A以下两个非打印字符。 大多数的终端仿真器配备了一个选项来启用UTF-8; 看看你是否可以启用(它会让你的生活更轻松)。

问题出在你的脚本,而不是奇怪的字符。



Answer 2:

尝试在记事本等++其他文本编辑器打开脚本,看看是否有存在的任何特殊字符。



Answer 3:

在命令行键入这两个命令。 一个或多个文件/目录你期待存在的,不存在的。

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


Answer 4:

该接受的答案解释该问题,感谢@nneonneo。 这是你可以速战速决做什么:

A)与检查区域设置:

  locale

B)调用脚本之前,或在您的bash脚本尝试的顶部:

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


文章来源: bad character showing up in bash script execution