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

Vue implements login verification code

This article example shares the specific code of ...

Detailed explanation of group by and having in MySQL

The GROUP BY syntax can group and count the query...

A brief talk about MySQL pivot tables

I have a product parts table like this: part part...

Examples of using temporary tables in MySQL

I've been a little busy these two days, and t...

How to set the position of the block element in the middle of the window

How to set the position of the block element in t...

Detailed explanation of MySQL precompilation function

This article shares the MySQL precompilation func...

Detailed explanation of object literals in JS

Table of contents Preface 1. Set the prototype on...

Solution to incomplete text display in el-tree

Table of contents Method 1: The simplest way to s...

HTML Basics: HTML Content Details

Let's start with the body: When viewing a web ...

Vue Element front-end application development: Use of API Store View in Vuex

Table of contents Overview 1. Separation of front...

30 minutes to give you a comprehensive understanding of React Hooks

Table of contents Overview 1. useState 1.1 Three ...

MySQL replication mechanism principle explanation

Background Replication is a complete copy of data...

Implementation of WeChat applet message push in Nodejs

Select or create a subscription message template ...

Docker volumes file mapping method

background When working on the blockchain log mod...