- How to run .sh or Shell Script file in Windows 10
- How to run .sh or Shell Script file in Windows 10
- 1] Execute Shell Script file using WSL
- 2] Execute Shell Script using Ubuntu on Windows 10
- Related Posts
- Windows Subsystem for Linux has no installed distributions
- Failed to Fork error with Ubuntu on Windows 10
- WslRegisterDistribution failed with error 0x8007019e and 0x8000000d – WSL
- [email protected]
- Primary Sidebar
- Information Security Squad
- 🐧 Как запустить файл .sh или Shell скрипт в Windows 10
- Как запустить файл .sh или скрипт шелла в Windows 10
- 1] Выполнить файл скрипта оболочки, используя WSL
- 2] Выполнить скрипт оболочки, используя Ubuntu в Windows 10
- How can I run a shell script in Windows? [duplicate]
- 8 Answers 8
- Execute shell script from power shell in windows machine
- 2 Answers 2
- Not the answer you’re looking for? Browse other questions tagged linux bash shell or ask your own question.
- Related
- Hot Network Questions
- Subscribe to RSS
- Running a shell script through Cygwin on Windows
- 6 Answers 6
How to run .sh or Shell Script file in Windows 10
Shell Scripts or .SH files are like batch files of Windows which can be executed in Linux or Unix. It is possible to run .sh or Shell Script file in Windows 10 using Windows Subsystem for Linux. In this post, we will show you how to run a Shell Script file in Windows 10.
How to run .sh or Shell Script file in Windows 10
Bash is a Unix shell and command language which can run Shell Script files. You do not need to install Ubuntu or any other Linux Distros unless your scripts need the support of the real Linux kernel. We will share both the methods.
- Execute Shell Script file using WSL
- Execute Shell Script using Ubuntu on Windows 10
1] Execute Shell Script file using WSL
Install WSL or Windows Subsystem for Linux
Go to Settings > Update & Security > For Developers. Check the Developer Mode radio button. And search for “Windows Features”, choose “Turn Windows features on or off”.
Scroll to find WSL, check the box, and then install it. Once done, one has to reboot to finish installing the requested changes. Press Restart now. BASH will be available in the Command Prompt and PowerShell.
Execute Shell Script Files
- Open Command Prompt and navigate to the folder where the script file is available.
- Type Bash script-filename.sh and hit the enter key.
- It will execute the script, and depending on the file, you should see an output.
On a Linux platform, you usually use SH, but here you need to use BASH. That said, BASH in Windows has its limitations, so if you want to execute in a Linux environment, you need to install Ubuntu or anything similar.
2] Execute Shell Script using Ubuntu on Windows 10
Make sure you have Ubuntu or any other Linux distros installed. Ubuntu will mount or make all your Windows directories available under /mnt. So the C drive is available at /mnt/C. So if the desktop will be available at /mnt/c/users/ /desktop.
Now follow these steps
- Type Bash in run prompt, and it will launch the distro prompt.
- Navigate to the folder using “cd” command to the folder where the scripts are available.
- Type “sh script.sh” and hit enter.
It will execute the script, and if they have a dependency on any of core Linux features.
Since Linux is now available in Windows, you need not use any third party applications like Cygwin. WSL should be enough for most of the scenarios to help you run a shell script in Windows 10.
Date: July 15, 2019 Tags: WSL
Related Posts
Windows Subsystem for Linux has no installed distributions
Failed to Fork error with Ubuntu on Windows 10
WslRegisterDistribution failed with error 0x8007019e and 0x8000000d – WSL
[email protected]
Ashish is a veteran Windows, and Xbox user who excels in writing tips, tricks, and features on it to improve your day to day experience with your devices.
Primary Sidebar
report this ad
Information Security Squad
stay tune stay secure
- Home
- 2019
- Июль
- 15
- 🐧 Как запустить файл .sh или Shell скрипт в Windows 10
🐧 Как запустить файл .sh или Shell скрипт в Windows 10
Шелл скрипты или .SH файлы похожи на командные файлы Windows, которые могут выполняться в Linux или Unix.
В Windows 10 можно запустить файл .sh или скрипт оболочки, используя подсистему Windows для Linux.
В этом руководстве мы покажем вам, как запустить файл скрипта оболочки в Windows 10.
Как запустить файл .sh или скрипт шелла в Windows 10
Bash – это оболочка и командный язык Unix, который может запускать файлы скрипты .sh.
Вам не нужно устанавливать Ubuntu или любые другие дистрибутивы Linux, если ваши скрипты не нуждаются в поддержке реального ядра Linux.
Мы поделимся обоими методами.
- Выполнить файл скрипт оболочки, используя WSL
- Выполнить скрипт оболочки с помощью Ubuntu в Windows 10
1] Выполнить файл скрипта оболочки, используя WSL
Установите WSL или Windows Subsystem для Linux
Перейдите в Настройки> Обновление и безопасность> Для разработчиков.
Проверьте переключатель режима разработчика.
Поищите «Функции Windows», выберите «Включить или отключить функции Windows».
Прокрутите, чтобы найти WSL, установите флажок и установите его.
После этого необходимо перезагрузить компьютер, чтобы завершить установку запрошенных изменений.
Нажмите Перезагрузить сейчас.
BASH отныне будет доступен в командной строке и PowerShell.
Выполнить файлы скриптов оболочки
- Откройте командную строку и перейдите в папку, где доступен файл скрипта
- Введите Bash script-filename.sh и нажмите клавишу Enter.
- Система выполнит скрипт, и в зависимости от файла вы должны увидеть вывод.
На платформе Linux вы обычно используете SH, но здесь вам нужно использовать BASH.
Тем не менее, BASH в Windows имеет свои ограничения, поэтому, если вы хотите выполнить их в среде Linux, вам нужно установить Ubuntu или что-то подобное.
2] Выполнить скрипт оболочки, используя Ubuntu в Windows 10
Убедитесь, что у вас установлена Ubuntu или любой другой дистрибутив Linux.
Ubuntu смонтирует или сделает все ваши каталоги Windows доступными в /mnt.
Таким образом, диск C доступен по адресу /mnt/C.
Таким образом рабочий стол будет доступен по адресу /mnt/c/users/ /desktop.
Теперь следуйте этим шагам
- В командной строке введите Bash, и система запустит приглашение дистрибутива.
- Перейдите в папку с помощью команды «cd» , где доступны скрипты.
- Введите «sh script.sh» и нажмите Enter
Система выполнит скрипт
Поскольку Linux теперь доступен в Windows, вам не нужно использовать какие-либо сторонние приложения, такие как Cygwin.
WSL должно быть достаточно для большинства скриптов, чтобы помочь вам запустить эти самые крипты оболочки в Windows 10.
How can I run a shell script in Windows? [duplicate]
I’m a Mac user and new to Windows. How can I execute a shell script in Windows?
Generally, I would save the text file with the extension .sh and run it via Terminal. But how could I do that in Windows?
8 Answers 8
Scripts with a .sh suffix are generally Bourne shell scripts (or bash, or ksh, or zsh — all shells derived from the Bourne shell). (Note that on Unix-like systems, including MacOS, the .sh suffix isn’t necessary; the OS looks at the #!/bin/sh line at the top of the script to determine how to execute it.)
Windows doesn’t provide a Bourne-like shell.
You can install Cygwin, which provides a Unix-like environment under Windows — but it doesn’t have a particularly «native» environment. (Editorial comment: Cygwin is great for people like me who need to use Windows but would really rather be using Unix.)
There are other Unix-like subsystems that run under Windows, including MinGW and the Windows Services for UNIX package provided by Microsoft.
Or, instead of trying to write and run Unix-like shell scripts, you can write Windows batch files. These generally have a .bat or .cmd suffix. They use the same commands and syntax as the Windows interactive command prompt.
There’s also the relatively new Windows PowerShell; I’m not familiar with it myself, but I’ve heard good things about it.
You can use Cygwin. It provides linux like environment in windows.
On Win the common extensions are .bat or .cmd . A good source for the commands used in Windows shell is ss64 — for CMD and PowerShell.
Cygwin is not a «must». It is just giving you the Linux style — use BASH on Win.
UWIN is a computer software package created by David Korn which allows programs written for the operating system Unix be built and run on Microsoft Windows with few, if any, changes. Some of the software development was subcontracted to Wipro, India.
Salient features of UWIN
- Access to almost all the command line tools from Unix on windows. 245 command line tools to be exact.
- Comes bundled with the original Unix compiler ‘cc’ as well as a plethora of tools like ‘make’ and the necessary libraries which allow Unix applications to be build and run on Windows machines with very little or no changes in the source code.
- Option to use other compilers like Visual C++ or Mingw to compile programs. Full fledged Perl package.
- X windows libraries for those who aspire to develop X applications on windows. Though to run those applications in Windows, you need an X server which is not bundled with UWIN.
- UWIN comes with a control panel applet (accessed through ‘Start->Settings->Control Panel->UWIN’) which can be used to configure some of the UWIN system parameters.
- Run Unix applications natively in Windows in full speed.
- Use the full power of Unix command line tools on Windows.
- The korn shell bundled with UWIN makes a Unix user feel right at home in a Windows environment.
- Develop and run UNIX applications on Windows.
- Develop X applications on the Windows platform.
Drawbacks of UWIN
- UWIN does not come bundled with a X server so a user will not be able to run X applications on windows. Though there are third party commercial X servers available which can fill this gap.
- UWIN is not released under the GPL but is free to download and use for educational and non-commercial purposes
That software was used to teach us Linux Command when i was in college.. really good one..
Cygwin is a Unix-like environment and command-line interface for Microsoft Windows.
Good about is that Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment.
Interix
Interix is a component of the Services for Unix (SFU) release 3.0 and 3.5 (this last one is distributed freely).
The most recent releases of Interix, 5.2 and 6.0, are components of the Windows Server 2003 R2, Windows Vista Enterprise and Ultimate editions and Windows Server 2008 under the name SUA (Subsystem for Unix-based Applications) Version 6.1 is included in Windows 7 (Enterprise and Ultimate) and Windows Server 2008 R2 (all editions)
Execute shell script from power shell in windows machine
I am trying to execute shell script from power shell in windows machine. So starting wrote the shell script and invoked into the linux box by using below command:
So it copied. After that when i am executing by using below command:
It’s not working in the sense getting error like:
If any valuable suggestions appreciable and thanks in advance.
2 Answers 2
I haven’t used much windows text-editors, but «^M: bad interpreter: No such file or directory» — indicates that there is windows-version of carriage return. So it might help just to convert your script file to unix-style.
first install the package
after that run the below command
after that assaign the execute permission to the script file
at last give the script file path then your script will be executed.
Not the answer you’re looking for? Browse other questions tagged linux bash shell or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Running a shell script through Cygwin on Windows
I have a bunch of shell scripts that used to run on a Linux machine. Now, we’ve switched over to Windows, and I need to run these scripts there. I have Cygwin installed, but is there a way to make the script run using Cygwin, but the call is made from Windows batch?
6 Answers 6
Sure. On my (pretty vanilla) Cygwin setup, bash is in c:\cygwin\bin so I can run a bash script (say testit.sh ) from a Windows batch file using a command like:
. which can be included in a .bat file as easily as it can be typed at the command line, and with the same effect.
One more thing — if You edited the shell script in some Windows text editor, which produces the \r\n line-endings, cygwin’s bash wouldn’t accept those \r . Just run dos2unix testit.sh before executing the script:
If you have access to the Notepad++ editor on Windows there is a feature that allows you to easily get around this problem:
- Open the file that’s giving the error in Notepad++.
- Go under the «Edit» Menu and choose «EOL Conversion»
- There is an option there for «UNIX/OSX Format.» Choose that option.
- Re-save the file.
I did this and it solved my problems.
Hope this helps!
Just wanted to add that you can do this to apply dos2unix fix for all files under a directory, as it saved me heaps of time when we had to ‘fix’ a bunch of our scripts.
I’d do it as a comment to Roman’s answer, but I don’t have access to commenting yet.
The existing answers all seem to run this script in a DOS console window.
This may be acceptable, but for example means that colour codes (changing text colour) don’t work but instead get printed out as they are:
I found this solution some time ago, so I’m not sure whether mintty.exe is a standard Cygwin utility or whether you have to run the setup program to get it, but I run like this:
. this causes the script to run in a Cygwin BASH console instead of a Windows DOS console.
If you don’t mind always including .sh on the script file name, then you can keep the same script for Cygwin and Unix (Macbook).
To illustrate:
1. Always include .sh to your script file name, e.g., test1.sh
2. test1.sh looks like the following as an example:
#!/bin/bash echo ‘$0 = ‘ $0 echo ‘$1 = ‘ $1 filepath=$1 3. On Windows with Cygwin, you type «test1.sh» to run
4. On a Unix, you also type «test1.sh» to run
Note: On Windows, you need to use the file explorer to do following once:
1. Open the file explorer
2. Right-click on a file with .sh extension, like test1.sh
3. Open with. -> Select sh.exe
After this, your Windows 10 remembers to execute all .sh files with sh.exe.
Note: Using this method, you do not need to prepend your script file name with bash to run