转换Bash脚本代码,用于代码bat文件窗口

时间:2015-09-24 21:15:04

标签: linux windows bash batch-file

我为Linux编写了这个bash脚本,我希望有人将此脚本转换为bat(文件)for windows。

#!/bin/bash

if curl -s --head http://google.com/ | grep "200 OK" > /dev/null
then 
    yes | cp -i /etc/hosts_bk /etc/hosts
else 
    echo "127.0.0.1 example.com" > /etc/hosts
    echo "127.0.0.1 www.example.com" >> /etc/hosts
fi

1 个答案:

答案 0 :(得分:0)

@echo off

curl -s --head http://google.com/ | findstr /c:"200 OK" >nul 2>&1

if errorlevel 1 (
    :: "200 OK" not found
    echo yes | copy /-Y %windir%\System32\Drivers\etc\hosts_bk %windir%\System32\Drivers\etc\hosts
) else (
    :: "200 OK" found
    echo "127.0.0.1 example.com"> %windir%\System32\Drivers\etc\hosts
    echo "127.0.0.1 www.example.com">> %windir%\System32\Drivers\etc\hosts
)
exit /b 0
相关问题