The method of executing sh File by linux
This article mainly introduces the method of implementing sh files by linux, which has a certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
Linux, there are two ways to use commands to execute .sh files:
1. Directly. / add the file name .sh. For example, run hello.sh as. / hello.sh [hello.sh must have x permission]
2. Add the file name .sh directly to sh. For example, run hello.sh as sh hello.sh [hello.sh may not have x permission]
Method 1: execute .sh files in the current directory
[step 1] cd to the directory where the .sh file is located
For example, take the hello.sh file as an example, as shown below
[step 2] add x execution permissions to the .sh file
For example, take the hello.sh file as an example, chmod uplix hello.sh, as shown in the following figure
[step 3]. / execute the .sh file
For example, take the hello.sh file as an example. / hello.sh can execute the hello.sh file, as shown in the following figure
[step 4] sh executes the .sh file
Take the hello.sh file as an example, sh hello.sh can execute the hello.sh file, as shown below
Method 2: execute .sh file by absolute path
The following three methods are fine, as shown in the following figure
. / home/test/shell/hello.sh/home/test/shell/hello.shsh / home/test/shell/hello.sh
Note: when executing with ". /" plus the file name .sh, you must add x execution permission to the .sh file.
Thank you for reading this article carefully. I hope it will be helpful for everyone to share the methods and contents of linux's implementation of sh files. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!