Shell脚本错误

时间:2012-10-30 15:32:10

标签: linux shell

我有这个shell脚本,我不断收到奇怪的错误。其中一个是需要做的。另一个是找不到config.txt但我在.sh脚本的目录中有它。

以下是错误打印输出:

jmgreen@jdev:~/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:

jmgreen@jdev:~/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

1 个答案:

答案 0 :(得分:1)

首先,将cat $strLocalDir"config.txt"替换为cat "${strLocalDir}config.txt"

然后,检查config.txt包含什么?这将被移动到$ URLS变量,可能它没有很好地形成。

如果遇到此类问题,请尝试插入调试语句,例如print。每次需要时测试变量的值,您将更准确地知道代码在哪里失败。