How to Run Shell Script
Ads by Google
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:
- Search “Settings” in the search bar.
- Click on “Update & Security” option.
- Click on “For Developers”.
- Check the Developer Mode radio button in the third number.
- And search for “Windows Features”.
- Choose “Turn Windows features on or off ( https://www.thewindowsclub.com/ways-to-enable-or-disable-optional-windows-features ) ”.
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?
- Select the file using mouse.
- Right-click on the file.
- Choose Properties:
- Click Permissions tab.
- Select Allow executing file as a program:
- 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?
Test Test Test:
- Run your test script without cron to make sure it actually works.
- Make sure you saved your command in cron, use sudo crontab -e.
- Reboot the server to confirm it all works sudo @reboot.
How do I run a .sh file in command prompt?
- 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.
How do I run a shell script after one?
They need each other to work, so it should go script1.sh -> script2.sh -> script3.pl.
- script1.sh needs 2 files inputted.
- script2.sh needs to output a .csv.
- 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?
How do I run multiple shell scripts sequentially from one script?
How do I run multiple commands in bash script?
How do I run multiple commands in Shell?
How do you put multiple commands in one command block?
How do I run multiple command prompts?
How do I run multiple commands in Dockerfile?
How do I run multiple batch files after one?
How do you join more than one command in Unix?
How do I write a script in Linux?
How do I run two parallel commands in Linux?
- Create a file using a vi editor(or any other editor). Name script file with extension . sh.
- Start the script with #! /bin/sh.
- Write some code.
- Save the script file as filename.sh.
- For executing the script type bash filename.sh.
How do bash scripts work?
Ads by Google