1

我正在编写一个在 Windows 的 cygwin 控制台上运行的 shell 脚本,我的脚本看起来像这样

#!/usr/bin/bash

cmd /c start /d "C:\cygwin\bin" ipconfig | findstr /R /C:"IPv4 Address"
ipconfig #to print 
route add 10.2.139.1 192.168.104.1

但是,当我在 cygwin 控制台上执行此脚本时,它显示以下错误,即使我更改为 ipconfig \all 它也不起作用

Error: unrecognized or incomplete command line.

USAGE:
    ipconfig [/allcompartments] [/? | /all |

我正在尝试通过执行脚本并添加到路由表来动态获取 IP 地址

谢谢,罗希特

4

1 回答 1

1

我不知道您为什么使用 cygwin 而不是 cmd.exe 来执行此操作,您使用它的目的以及为什么使用它start,但是,您所缺少的只是一个选项/b

cmd /c start /d "C:\cygwin\bin" /b ipconfig | findstr /R /C:"IPv4 Address" 

并且start冗余如下:

cmd /c ipconfig | findstr /R /C:"IPv4 Address"

/b只是抑制新创建的cmd.exe背景窗口。

于 2015-08-06T13:20:21.000 回答