- 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 to run shell script located on Linux server from Windows environment?
- 1) Script runs correctly when I log in to the server via MobaXterm
- 2) Same shell script runs successfully via .cmd manually
- 1 Answer 1
- How can I run a shell script in Windows? [duplicate]
- 8 Answers 8
- How to run shell script located on Linux server from Windows environment?
- 1) Script runs correctly when I log in to the server via MobaXterm
- 2) Same shell script runs successfully via .cmd manually
- 1 Answer 1
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 to run shell script located on Linux server from Windows environment?
I am trying to run a shell script located on a Linux server from Windows. The shell script does two things:
- Do a sed command to replace text in an .sql file in the same directory.
- Run the .sql file with sqlplus .
The shell script:
(My database is located on the same Linux server.)
1) Script runs correctly when I log in to the server via MobaXterm
- Connect to server with userID .
- Set my_env .
- cd to the shell script’s directory.
- Run script with ./myscript.sh with arguments.
2) Same shell script runs successfully via .cmd manually
- Create a Windows script test.cmd on my Windows PC.
In the .cmd file I have the line:
After the console window pops up, I repeat the steps 2 to 4 and script runs successfully.
What I am failing to do so is to automate the whole process.
Here’s the line in my .cmd file which I attempted:
I can see the arguments passed correctly using multiple echo in the shell script. However, the shell script fails to locate the .sql file.
I also tried below, but unfortunately with same result:
Where file command.txt contains:
I do not know why it is not working, especially when 2) works and the script is relatively simple.
Do I assume things incorrectly about plink (path, variable, etc.)?
Is Cygwin the only way out?
I tried not to rely on yet another tool as I have been using plink .
EDIT: While the line
fails to run on the .sh, i can run it on the .cmd file itself via:
Hence I am suspecting the problem comes from the .sh file not having the required components to run (i.e. set env variable, path, etc)
1 Answer 1
This is not a solution but partially fixed some issue, thanks to Martin Prikryl and Mofi’s input:
in the command.txt, the following needs to be set:
ORACLE_SID
ORACLE_HOME
PATH
after these are set, the sqlplus and sed will work normally. However, passing values from .cmd through plink to Linux’s shell script seems to have issue with the actual value being passed. The variable will have the assigned value along with some unreadable characters. In this case,
login fails because arg2 contains some other char.
this line also fails as it will try to opens 2 files, one being called sequence.myvalue and another one called «%s», which i suspect the assigned variable contains some sort of unreadable nextline character.
EDIT: fixed, we can use the same treatment from sed — run sqlplus directly from plink instead of passing value and running a .sh script in Linux:
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)
How to run shell script located on Linux server from Windows environment?
I am trying to run a shell script located on a Linux server from Windows. The shell script does two things:
- Do a sed command to replace text in an .sql file in the same directory.
- Run the .sql file with sqlplus .
The shell script:
(My database is located on the same Linux server.)
1) Script runs correctly when I log in to the server via MobaXterm
- Connect to server with userID .
- Set my_env .
- cd to the shell script’s directory.
- Run script with ./myscript.sh with arguments.
2) Same shell script runs successfully via .cmd manually
- Create a Windows script test.cmd on my Windows PC.
In the .cmd file I have the line:
After the console window pops up, I repeat the steps 2 to 4 and script runs successfully.
What I am failing to do so is to automate the whole process.
Here’s the line in my .cmd file which I attempted:
I can see the arguments passed correctly using multiple echo in the shell script. However, the shell script fails to locate the .sql file.
I also tried below, but unfortunately with same result:
Where file command.txt contains:
I do not know why it is not working, especially when 2) works and the script is relatively simple.
Do I assume things incorrectly about plink (path, variable, etc.)?
Is Cygwin the only way out?
I tried not to rely on yet another tool as I have been using plink .
EDIT: While the line
fails to run on the .sh, i can run it on the .cmd file itself via:
Hence I am suspecting the problem comes from the .sh file not having the required components to run (i.e. set env variable, path, etc)
1 Answer 1
This is not a solution but partially fixed some issue, thanks to Martin Prikryl and Mofi’s input:
in the command.txt, the following needs to be set:
ORACLE_SID
ORACLE_HOME
PATH
after these are set, the sqlplus and sed will work normally. However, passing values from .cmd through plink to Linux’s shell script seems to have issue with the actual value being passed. The variable will have the assigned value along with some unreadable characters. In this case,
login fails because arg2 contains some other char.
this line also fails as it will try to opens 2 files, one being called sequence.myvalue and another one called «%s», which i suspect the assigned variable contains some sort of unreadable nextline character.
EDIT: fixed, we can use the same treatment from sed — run sqlplus directly from plink instead of passing value and running a .sh script in Linux: