在Windows 7上运行bash脚本Cygwin中 [英] running bash script in cygwin on windows 7

查看:355
本文介绍了在Windows 7上运行bash脚本Cygwin中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行的cygwin在Windows下面的bash脚本7

I am trying to run the below bash script in cygwin on windows 7

REPEATTIMES="$1"

if [ $# = 0 ]; then

    echo "Usage: fetch topN repeatTimes"
    exit 1
fi

for (( i=1; i<=$REPEATTIMES; i++ ))
do
    echo "ITERATION: $i"
    echo "GENERATING"

    log=thelogs/log 

    bin/nutch generate crawl/segment -topN 10 > $log
    batchId=`sed -n 's|.*batch id: \(.*\)|\1|p' < $log`

    echo "batch id: $batchId "

    # rename log file by appending the batch id
    log2=$log$batchId
    mv $log $log2
    log=$log2

    echo "FETCHING"
    bin/nutch fetch crawl/segments/$batchId >> $log

    echo "PARSING"
    bin/nutch parse crawl/segments/$batchId >> $log


    echo "UPDATING DB"
    bin/nutch updatedb crawl/crawldb crawl/segments/$batchId >> $log

    echo "Done "

done


但是,当我运行它,我得到的错误:


But when i run it i get the error :

line 11 :syntax error near unexpected token '$'\r'

line 11 :'for (( i=1; i<= REPEATTIMES; i++ ))

该脚本正常工作Ubuntu的服务器上。但我现在需要在Windows机器上运行它。

The script works fine on a ubuntu server. But i need to run it now on a windows machine.

推荐答案

Cygwin的最新版本似乎只支持Unix的格式的文件(即\\ n作为相对于DOS / Windows的新行\\ r \\ n换行)

The latest version of Cygwin seems to only support files in Unix format (i.e. with \n for newlines as opposed to the DOS/Windows \r\n newline).

要解决这个问题,运行/bin/dos2unix.exe实用工具,让您的脚本作为参数传递给命令:

To fix this, run the /bin/dos2unix.exe utility, giving your script as the argument to the command:

e.g. /bin/dos2unix.exe myScript.sh

这将其转换为Unix格式,然后你应该能够运行它。

This will convert it to Unix format and you then should be able to run it.

这篇关于在Windows 7上运行bash脚本Cygwin中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆