【问题标题】:Can I run a Linux shell script in Windows?我可以在 Windows 中运行 Linux shell 脚本吗?
【发布时间】:2015-03-07 16:05:18
【问题描述】:

我在 Linux 上创建了 Shell 脚本,它运行良好。

现在我想使用gitbash 在 Windows 上运行相同的脚本。 (仅更改了 Windows 的文件路径)

我很困惑:

  • 是否需要根据Windows语法shell脚本重新编写一个新的shell脚本?

  • Linux 语法 shell 脚本可以在 Windows 上运行而不需要更改吗?

根据differences-between-windows-batch-and-linux-bash-shell-script-syntax

【问题讨论】:

  • 你可以在windows上运行bash,以及一些其他的UNIX shell(ashtcsh)......但是,你可能会遇到很多小问题,如Windows & UNIX 非常不同......如果你想制作跨平台的东西,我建议使用 Python、Java、Ruby 或其他更适合这项工作的语言。
  • 如果你写了一个Shell脚本,你可以在Windows中使用cygwin运行它。
  • 这里下载cygwin
  • @fedorqui 在我的学习中 'cygwin' 和 'gitbash' 为 windows 做同样的事情

标签: linux windows shell git-bash


【解决方案1】:

当然可以。有一个名为cygwin 的工具可以让您这样做。

请注意,您必须检查路径是什么。如果是这样,请转到您愿意工作的路径并执行pwd。这样,您将获得Windows\kind\of\path

我一直在用它,效果很好。

【讨论】:

  • 太棒了!为 windows 环境更改 slash 让我的脚本工作并使用 cygwin
【解决方案2】:

你可以使用 Git Bash

这取决于脚本的高级程度,但简单的脚本可以在 Git Bash 中执行。

test.sh 包含:

#!/bin/bash
echo Hello World!

执行脚本:

./test.sh

输出:

Hello World!

Git Bash 与 Cygwin

回答你的问题:

@fedorqui 在我的学习中 'cygwin' 和 'gitbash' 做同样的事情 窗户

Git Bash

Git Bash 是轻量级的,仅用于处理:

  • 版本控制
  • 运行命令的外壳

阅读更多:http://openhatch.org/missions/windows-setup/install-git-bash

赛格温

  • 大量 GNU 和开源工具,它们提供 功能类似于 Windows 上的 Linux 发行版。
  • 提供大量 POSIX API 的 DLL (cygwin1.dll) 功能。

阅读更多:https://www.cygwin.com/

【讨论】:

  • 感谢教 Cygwin 的复杂脚本比 gitbash 的简单脚本更好。因为 Cygwin 在 windows 中带来了更大的 linux 环境。
猜你喜欢
  • 2011-11-26
  • 2019-03-16
  • 2014-09-04
  • 2013-05-08
  • 2017-03-09
  • 2012-05-21
  • 1970-01-01
  • 1970-01-01
  • 2017-09-24
相关资源
最近更新 更多