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

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

问题描述

我正在尝试在 Windows 7 上的 cygwin 中运行以下 bash 脚本

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 '$'
'

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 格式的文件(即用 换行而不是 DOS/Windows 换行).

The latest version of Cygwin seems to only support files in Unix format (i.e. with for newlines as opposed to the DOS/Windows 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 上的 cygwin 中运行 bash 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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