How To Run The Sh Script

Table of contents:

How To Run The Sh Script
How To Run The Sh Script

Video: How To Run The Sh Script

Video: How To Run The Sh Script
Video: How to run a Shell script on Windows 10 2024, May
Anonim

You have written a shell script, but you do not know how to run it. This is a problem many novice Linux users face. In order for the script to become runnable, it must be prepared in a special way. This can be done in different ways.

How to run the sh script
How to run the sh script

Instructions

Step 1

The easiest way is to make scripts executable and run them using the Midnight Commander program. Most Linux distributions already have it. However, it is usually missing from alt="Image" Linux and Ubuntu, in which case it must be installed by running the following command: On alt="Image" Linux, to install this program, you will have to download it as an RPM file and then install it. Change to the folder where the file is located using the cd command followed by the full path to that folder. Then run this command: rpm -i./filename.rpm

where filename.rpm is the file you downloaded. In Ubuntu, the download and installation process is automated, you will have to use just one command to start it: sudo apt-get install mc Execute all the above commands from root mode. There is no such mode in Ubuntu, so the sudo command is used before apt-get. Once Midnight Commander is installed, it can be launched by any user using the following command: mc

Step 2

If Midnight Commander is not used, you can change the permissions of the shell script file so that it can be executed with the following command: chmod 755 filename

where filename is the name of your script file. Now try running it:./ filename

Step 3

If you prefer to use the Midnight Commander, change the script permissions as follows. Launch this program, go to the folder with the file you created, move the pointer to it, then in the File menu find the Access Rights item. Check the boxes "Start / search for owner", "Start / search for group" and "Start / search for others" (some of them may not be installed if you do not want to allow other users to run the script). Save the settings with the "Install" button. Now the file name in the list will turn green, and an asterisk will appear to the left of it. By hovering over it and pressing the "Enter" key, you can run the file.

Recommended: