How to run .sh files in Linux system

How to run .sh files in Linux system

There are two ways to run .sh files in Linux system. For example, I have a datelog.sh file in the root directory.

The first method (this method requires chmod to make the file executable (x): chmod u+x datelog.sh):

1. In any path, enter the absolute path of the file /root/datelog.sh to execute the file (of course, if the permission is allowed)


2. cd to the directory of the datelog.sh file, and then execute ./datelog.sh


The second method (this method does not require the file to have executable permissions to run):

1. Add the file name to the file path, sh datelog.sh


2. In any path, add the file path and file name to sh: sh /root/ datelog.sh


Double-click the sh file in the desktop environment to run:

Mac:

1. Change the suffix sh to command: hello.sh->hello.command

2. Modify the executable permission: chmod u+x hello.command

Ubuntu:

1. Modify the executable permission: chmod u+x hello.sh

2. Open any folder and select [Edit] -> [Preferences] in the upper left corner.

Select [Run executable text files when opening them] to double-click to run.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Getting started with writing and running Linux shell (.sh) scripts

<<:  A simple way to implement all functions of shopping cart in Vue

>>:  What you need to understand about MySQL locks

Recommend

Solutions to the Problem of Creating XHTML and CSS Web Pages

The solutions to the problems encountered during x...

MySQL 8.0.15 installation and configuration graphic tutorial under Win10

This article records the installation and configu...

How to smoothly upgrade and rollback Nginx version in 1 minute

Today, let's talk about a situation that is o...

Example code for Html layered box-shadow effect

First, let’s take a look at the picture: Today we...

Three Ways to Lock and Unlock User Accounts in Linux

If you already have some kind of password policy ...

Disable IE Image Toolbar

I just tried it on IE6, and it does show the toolb...

js implements a simple English-Chinese dictionary

This article shares the specific code of js to im...

Linux command line quick tips: How to locate a file

We all have files stored on our computers -- dire...

How to delete folders, files, and decompress commands on Linux servers

1. Delete folders Example: rm -rf /usr/java The /...

The perfect solution for Vue routing fallback (vue-route-manager)

Table of contents Routing Manager background gett...

How to change the terminal to a beautiful command line prompt in Ubuntu 18

I reinstalled VMware and Ubuntu, but the command ...

jQuery achieves seamless scrolling of tables

This article example shares the specific code of ...