我有這個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
看起來非常像DOS換行符。 – tripleee
謝謝。我的文件中一定有一些隱藏的DOS換行符。 SED將他們全部移除。 – Evilsithgirl
[Bash寫入變量的可能重複? :命令未找到](http://stackoverflow.com/questions/7444953/bash-writing-variable-command-not-found) – tripleee