简体   繁体   English

我可以在Windows中运行Linux Shell脚本吗?

[英]Can I run a Linux shell script in Windows?

I created Shell Script on Linux and it runs fine. 我在Linux上创建了Shell脚本,并且运行良好。

Now I want to run the same script on Windows using gitbash . 现在,我想使用gitbash在Windows上运行相同的脚本。 (Only filepath changed for windows) (仅对于Windows更改了文件路径)

I am confused: 我很困惑:

  • do I need to write a new shell script again according to Windows syntax shell script? 我需要根据Windows语法Shell脚本再次编写新的Shell脚本吗?

or 要么

  • can a Linux syntax shell script run on Windows without changes? Linux语法Shell脚本可以在Windows上运行而无需更改吗?

According TO differences-between-windows-batch-and-linux-bash-shell-script-syntax 根据TO 之间的差异-Windows批处理和Linux Bash Shell脚本语法

Of course you can. 当然可以。 There is a tool called cygwin that allows you to do so. 有一个名为cygwin的工具可让您执行此操作。

Note that you have to check what the paths are. 请注意,您必须检查路径。 If so, go to the path you are willing to work on and do pwd . 如果是这样,请转到您愿意尝试的路径并执行pwd This way, you will get the Windows\\kind\\of\\path . 这样,您将获得Windows\\kind\\of\\path

I use it all the time and it works pretty fine. 我一直使用它,并且效果很好。

You can use Git Bash 您可以使用Git Bash

It depends on how advanced the scripts are, but simple scripts can be executed in Git Bash. 这取决于脚本的高级程度,但是可以在Git Bash中执行简单的脚本。

test.sh contains: test.sh包含:

#!/bin/bash
echo Hello World!

Execute script: 执行脚本:

./test.sh

Output: 输出:

Hello World!

Git Bash vs Cygwin 吉特·巴什vs赛格温

To answer your question: 要回答您的问题:

@fedorqui in my learning 'cygwin' And 'gitbash' do same stuff for windows 我学习的“ cygwin”中的@fedorqui和“ gitbash”在Windows中执行相同的操作

Git Bash 吉特·巴什

Git Bash is lightweight and only aims to handle: Git Bash是轻量级的,仅旨在处理:

  • version control 版本控制
  • a shell that runs commands 运行命令的外壳

Read more: http://openhatch.org/missions/windows-setup/install-git-bash 了解更多: http : //openhatch.org/missions/windows-setup/install-git-bash

Cygwin Cygwin的

  • a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows. GNU和开放源代码工具的大量集合,它们提供的功能类似于Windows上的Linux发行版。
  • a DLL (cygwin1.dll) which provides substantial POSIX API functionality. 提供实质性POSIX API功能的DLL(cygwin1.dll)。

Read more: https://www.cygwin.com/ 了解更多: https//www.cygwin.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM