2015-01-06 63 views
2

嘗試在done語句周圍執行下面的腳本時出現錯誤。代碼的要點是在記錄文件名中列出的文件的持續時間內執行while語句,以獲取我的分支文件夾中每個文件位置的修訂號。通過外殼程序自動化腳本編輯.CSV文件

filea=/home/filenames.log 
fileb=/home/actions.log 
filec=/home/revisions.log 
filed=/home/final.log 


count=1 
while read Path do 
Status=`sed -n "$count"p $fileb` 
Revision=`svn info ${WORKSPACE}/$Path | grep "Revision" | awk '{print $2}'` 
if `echo $Path | grep "UpgradeScript"` then 
Results="Reverted - ROkere" 
Details="Reverted per process" 
else if `echo $Path | grep "tsu_includes/shell_scripts"` then 
Results="Reverted - ROkere" 
Details="Reverted per process" 
else 
Results="Verified - ROkere" 
Details="" 
fi 
echo "$Path,$Status,$Revision,$Results,$Details" > $filed 
count=`expr $count + 1` 
done < $filea 

回答

0
  • dothen之前需要一個分號或換行符。
  • 變化else ifelif
  • 變化

    if `echo $Path | grep "UpgradeScript"` then 
    

    到(除反引號,用 「此處的字符串」,並-q選項的grep)

    if grep -q "UpgradeScript" <<< "$Path"; then 
    
  • 「申請」 不僅會只包含一行。我假設你要追加>>,而不是覆蓋>


其實,快速重寫。您正在從2個文件中讀取相應的行。在shell中完成這些操作更快,而不是爲文件中的每一行調用sed一次。

#!/bin/bash 
filea=/home/filenames.log 
fileb=/home/actions.log 
filec=/home/revisions.log # not used? 
filed=/home/final.log 

exec 3<"$filea" # open $filea on fd 3 
exec 4<"$fileb" # open $fileb on fd 4 

while read -u3 Path && read -u4 Status; do 
    Revision=$(svn info "$WORKSPACE/$Path" | awk '/Revision/ {print $2}') 
    if [[ "$Path" == *"UpgradeScript"* ]]; then 
     Results="Reverted - ROkere" 
     Details="Reverted per process" 
    elif [[ "$Path" == *"tsu_includes/shell_scripts"* ]]; then 
     Results="Reverted - ROkere" 
     Details="Reverted per process" 
    else 
     Results="Verified - ROkere" 
     Details="" 
    fi 
    echo "$Path,$Status,$Revision,$Results,$Details" 
done > "$filed" 

exec 3<&- # close fd 3 
exec 4<&- # close fd 4