Linux Shell脚本错误

Linux Shell脚本错误,linux,shell,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 (expectin

我有这个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

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

然后,检查config.txt包含哪些内容?这将被移动到$URL变量,可能它的格式不正确


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

看起来非常像DOS新行。谢谢。我的文件中一定有隐藏的DOS新行。一个SED把它们都删除了。非常感谢。这有助于使用SED命令删除DOS换行符。