2012-10-30 303 views
0

我有這個shell腳本,並且不斷收到奇怪的錯誤。其中之一是需要做的。另一個是找不到config.txt,但是我使用.sh腳本將其放在目錄中。Shell腳本錯誤

以下是錯誤的打印輸出:

[email protected]:~/citigetbash$ sh citiget.sh 
: not found 2: clear 
CITIGET 
config.txt: No such file or directory 

citiget.sh: 17: Syntax error: word unexpected (expecting "do") 

這裏是目錄的LS:

[email protected]:~/citigetbash$ ls 
citiget.sh config.txt docs 

這裏是我的shell腳本

#!/bin/bash 
clear 
strTitle="CITIGET" 
echo $strTitle 
#=====CONFIGURATION============================================================= 
strLocalDir="/home/jmgreen/citigetbash/" 
intMode=1 
intTry=5 
#=============================================================================== 
# 
# ===== Read in all the URLs 
strDir=$(pwd) 
URLS=$(cat $strLocalDir"config.txt") 
echo $URLS 
# ===== Get the file 
if [ $intMode = 1 ]; then 
    for u in $URLS; 
     do 
      # ===== Get the datestamp ready 
      ts=$(date +%Y%m%d%H%M%S); 
      echo "Trying..."$u 
      wget $u --no-check-certificate -t$intTry -a logfile.txt -O $strLocalDir"downloaded/"$ts".csv"; 
    done 
else 
    for u in $URLS; 
     do 
      # ===== Get the datestamp ready 
      ts=$(date +%Y%m%d%H%M%S); 
      wget $u -q --no-check-certificate -t$intTry -a logfile.txt -O $strLocalDir"downloaded/"$ts".csv"; 
    done 
fi 
# ===== Clear Screen? 
if [ $intMode = 1 ]; then 
    clear 
fi 
echo "===== DONE =====" 
exit 
+2

看起來非常像DOS換行符。 – tripleee

+0

謝謝。我的文件中一定有一些隱藏的DOS換行符。 SED將他們全部移除。 – Evilsithgirl

+0

[Bash寫入變量的可能重複? :命令未找到](http://stackoverflow.com/questions/7444953/bash-writing-variable-command-not-found) – tripleee

回答

1

首先,cat "${strLocalDir}config.txt"更換cat $strLocalDir"config.txt"

然後,檢查config.txt包含什麼?這將被移動到$ URLS變量,也許它不是很好形成。

當您遇到此類問題時,請嘗試插入調試語句,如打印。每次需要測試變量的值時,您都會更精確地知道代碼失敗的原因。

+0

非常感謝。這有助於使用SED命令刪除DOS換行符。 – Evilsithgirl