2013-08-06 68 views
0

我有一個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="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 

任何人都可以看到可能的問題或建議的方式,我可以去尋找其中的問題是什麼?

+1

檢查腳本中的* quote *字符。看起來你可能有不合需要的字符而不是''' – devnull

+1

嘗試調試你的腳本'bash -x ...'。 – devnull

+1

順便說一下,你應該總是使用'#!/ bin/bash -e',尤其是腳本這可能會產生危險的效果,你不希望出現'objpath ='get_path ...'''失敗的情況,並且以後會導致你使用'rm -rf/usr/$ objpath'(或其他同樣愚蠢的東西) – nneonneo

回答

3

那些â字符只是從您的shell打印出的損壞的智能報價。您的shell可能正在輸出UTF-8,但您的終端正在讀取ISO-8859-1。請注意,â是ISO-8859-1中UTF-8編碼的智能報價的呈現,其中兩個非可打印字符位於「大多數現代終端仿真器都帶有一個選項來啓用UTF-8;看看你是否可以啓用它(它會讓你的生活更輕鬆)。

問題出在你的腳本上,而不是有趣的角色。

+0

感謝這個,我懷疑這是非常像這樣的事情。我沒有找到違規字符的運氣,可能只需要重寫這個從頭開始 – Tristan

+0

有**沒有**的冒犯角色,這就是我想指出的,你的腳本可能使用了錯誤的路徑或其他東西 – nneonneo

+0

哦好吧有道理它是解析一個階段的路徑,但不是所有的串那些已經被「感染」的東西是這樣產生的,有些只是在腳本中自己編碼,但我遵循這一思路,看看我發現了什麼 – Tristan

0

嘗試在另一個文本編輯器(如Notepad ++)中打開腳本並查看是否存在任何特殊字符。

+0

感謝您的建議,但我已經這樣做了,仍然無法找到問題 – Tristan

0

從命令行鍵入這兩個命令。一個或多個您期望存在的文件/目錄不存在。

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