How to run Shell Script file in Windows 10

In this article we discussing about the script files, how to run script files on windows 10. There are two ways to run a shell script on windows 10

  • Run shell script files using WSL on windows 10
  • Run shell script or .sh using The Ubuntu on Windows 10

Run shell script files using WSL on windows 10

Windows users follow these steps and install PowerShell:

Click on the scroll and find the WSL, check the box and install ( https://www.thewindowsclub.com/run-bash-on-windows-10 ). After the installation finishes and requested changes. Click on the “Restart now” option. Now you can use BASH in the Command Prompt and PowerShell.

Run the Shell Script

Follow these steps to run the .sh file.

  • Click on the start button and open the Command Prompt. Using cd command open that folder where the script file is available.
  • Write the name of the Bash Script on command prompt and press Enter Button.

Script-filename.sh

  • After this command, your script will run and your system will show the output depending on the script and output will display.

Run shell script files using The Ubuntu on Windows 10

  • Click on the start button and search Bash, and launch the distro command prompt on your system.
  • Write the name of the Bash Script on command prompt and press Enter Button.

Script-filename.sh

  • Write the “ sh script.sh ” and press the Enter button.
  • After that, your script will execute and if it needs some dependency on any of the Linux features.

How to Run Shell Script in the Linux Operating System

Today, everybody knows about the importance of the Linux operating system. The Linux provides powerful command-line features. In the Linux, run script or .sh files follow these steps:

  • Open the terminal using shortcut key [ Ctrl + Alt + T ].
  • Using cd command open that folder or directory where the script file is available.
  • Before running script file set the Linux permissions for the script file.

chmod +x scriptname.sh

  • Now you can run script file using different commands

$ ./script-name-here.sh

sh scriptName.sh

bash scriptName.sh

How to Run Shell Script in the Linux as a Root

We know that Linux is the most powerful and secure operating system. Therefore sometimes the Linux does not give you access or permissions to write or run the files. We want to open the read/write modes or log in with Root user.

Follow these commands to run the script files as the root user:

  • Using this command “ sudo bash scriptName.sh ”.

After the above command, we to enter the root password.

OR

su –

“ su – ” command asks you to root password then you can run the script.

  • Now you are able to run the script file.

bash scriptName.sh

Example of Script File in the Linux

A simple example of script file running in the Linux:

Let’s we have script file with the name of “makesimplegui.sh”

chmod +x makesimplegui.sh

./makesimmplegui.sh

“ ./ ” means the scripting file is available in current directory.

bash makesimplegui.sh

OR

sh makesimplegui.sh

How to Run Shell Script in Ubuntu through GUI

The Linux flavours also provide Graphical User Interface for running script files. Follow these steps to run script files:

  • Select the script files that you want to run.
  • Right-click on that script file.
  • Click on the “ Properties ” option from the menu.
  • Press the “ Permissions ” tab on the new window.
  • On the bottom side click on the checkbox “ Allow execute the file as program ”.
  • Now you can run your file, select “ Run in the terminal ”. it will run on the terminal

How to Run Shell Script on MAC Terminal

MAC OS is also a powerful operating system in the modern era. MAC provides a better and secure operating system that supports all kind of platform, softwares and Tools. MAC provides a good command line terminal for interacting with your PC. We can also run shell script files on MAC.

Follow these commands for running script files:

  • Type the command

Sh scriptName

OR

bash scriptName

  • Now start execution of the script file and give it permissions similar in Linux operating system.
  • ./scriptName [ if your file is in current directory ].
  • Permissions command in MAC OS.

chmod +x scriptName
./scriptName

How do I run a .sh file in Linux?

GUI method to run . sh file
  1. Select the file using mouse.
  2. Right-click on the file.
  3. Choose Properties:
  4. Click Permissions tab.
  5. Select Allow executing file as a program:
  6. Now click the file name and you will be prompted. Select “Run in the terminal” and it will get executed in the terminal.

How do I run a .sh file automatically?

local file using nano or gedit editor and add your scripts in it. File path could be /etc/rc. local or /etc/rc. d/rc.

Test Test Test:

  1. Run your test script without cron to make sure it actually works.
  2. Make sure you saved your command in cron, use sudo crontab -e.
  3. Reboot the server to confirm it all works sudo @reboot.

How do I run a .sh file in command prompt?

Execute Shell Script Files
  1. Open Command Prompt and navigate to the folder where the script file is available.
  2. Type Bash script-filename.sh and hit the enter key.
  3. It will execute the script, and depending on the file, you should see an output.

How do I run a shell script after one?

One requires a user to input a file.

They need each other to work, so it should go script1.sh -> script2.sh -> script3.pl.

  1. script1.sh needs 2 files inputted.
  2. script2.sh needs to output a .csv.
  3. script3.pl runs on the . csv created and needs an input that I want to prompt the user for.

How do you sleep in a shell script?

Does shell script run sequentially?

/bin/sleep is Linux or Unix command to delay for a specified amount of time. You can suspend the calling shell script for a specified time. For example, pause for 10 seconds or stop execution for 2 mintues. In other words, the sleep command pauses the execution on the next shell command for a given time.

How do I run multiple shell scripts sequentially from one script?

3 Answers. They are executed sequentially.

How do I run multiple commands in bash script?

Just like && , || is a bash control operator: && means execute the statement which follows only if the preceding statement executed successfully (returned exit code zero). || means execute the statement which follows only if the preceding statement failed (returned a non-zero exit code).

How do I run multiple commands in Shell?

To run multiple commands in a single step from the shell, you can type them on one line and separate them with semicolons. This is a Bash script!! The pwd command runs first, displaying the current working directory, then the whoami command runs to show the currently logged in users.

How do you put multiple commands in one command block?

The semicolon (;) operator allows you to execute multiple commands in succession, regardless of whether each previous command succeeds. For example, open a Terminal window (Ctrl+Alt+T in Ubuntu and Linux Mint). Then, type the following three commands on one line, separated by semicolons, and press Enter.

How do I run multiple command prompts?

To make your command block run multiple commands, you will need to summon FallingSand or falling_block (depending on your version of Minecraft) with command blocks and redstone blocks for each command. The command blocks will be stacked one on top of the other and contain the individual command.

How do I run multiple commands in Dockerfile?

Try using the conditional execution & or the && between each command either with a copy and paste into the cmd.exe window or in a batch file. Additionally, you can use the double pipe || symbols instead to only run the next command if the previous command failed.

How do I run multiple batch files after one?

&& is a function of the shell, which is used to chain commands together. In fact, when you use this syntax in a Dockerfile, you are actually leveraging the shell functionality. If you want to have multiple commands with the exec form, then you have do use the exec form to invoke the shell as follows

How do you join more than one command in Unix?

Launching many command prompts can be done as below. start cmd /k Call rc_hub. bat 4444 start cmd /k Call rc_grid1. bat 5555 start cmd /k Call rc_grid1.

How do I write a script in Linux?

In UNIX/Linux style “shell” command line interpreters, you can type two or more commands separated by a semicolon to run them consecutively – or you can place an ‘&’ character after one or more of the commands to run them “in background” so that they are both running together.

How do I run two parallel commands in Linux?

How to Write Shell Script in Linux/Unix
  1. Create a file using a vi editor(or any other editor). Name script file with extension . sh.
  2. Start the script with #! /bin/sh.
  3. Write some code.
  4. Save the script file as filename.sh.
  5. For executing the script type bash filename.sh.

How do bash scripts work?

In case you need to execute several processes in batches, or in chunks, you can use the shell builtin command called “wait”. See below. The first three commands wget commands will be executed in parallel. “wait” will make the script wait till those 3 gets finished.