我在执行Linux bash脚本时遇到错误

时间:2016-06-24 11:13:53

标签: linux bash unix scripting

我在文件" handoff"执行脚本时遇到以下错误:

sh handoff
'andoff: line 5: syntax error near unexpected token `do
'andoff: line 5: `  do

以下是文件的内容:

cat handoff
while [ 1 ]; do
   credencemove
  k=0
  for n in `cat credencemove.txt`
  do
    status[$k]=$n
    k=`expr $k + 1`
  done
  for m in `cat logsequence.lst`
  do
    status[$k]=$m
    k=`expr $k + 1`
  done
   ls -lrt | grep arch_credence_1 | tail -1 | cut -c 68- | tr -d 'ah_.log.gz' | cut -c -5 > credencereceived.txt
  for o in `cat credencereceived.txt`
  do
    status[$k]=$o
    k=`expr $k + 1`
  done
   clear
   tput bold
   echo "         Received Applied Moved"
   echo "         ========================"
   echo " "
   echo " Credence1 -> ${status[6]} \c"
   echo "  ${status[3]} \c"
   echo "  ${status[0]}"
   tput rmso
   echo " "
   echo "Waiting 15 Minuites for applying further logs..."
   echo "Press ctrl + c to exit"
   sleep 900
done

1 个答案:

答案 0 :(得分:1)

您的bash脚本中有回车符(\r),就好像脚本是在Windows文本编辑器上创建的一样。

使用dos2unix清理脚本。