1024programmer Linux How to run shell scripts in Linux-linux operation and maintenance

How to run shell scripts in Linux-linux operation and maintenance

$ bash test.sh

2、path/ script-name or ./script-name

means to execute the script in the current path (the script needs to have execution permission), you need to change the permission of the script file to executable (that is, the file permission attribute for x bits). The specific method is: chmod a+x script-name. Then the script can be executed by executing the absolute path or relative path of the script.

Note: In the production environment, the operation and maintenance personnel forgot to set the executable permission for the script, and then used it directly, resulting in an error. Therefore, the first bash script-name is recommended.

$ chmod +x test.sh
 $ ./test.sh
 $ /home/me/test.sh

3, source script-name or. script-name

The function of the source or “.” command is : Read in the script and execute the script, that is, execute the commands and statements of the relevant script file loaded and executed by source or “.” in the current shell, instead of generating a sub-shell to execute the commands in the file.

Note: This is the biggest difference from other ways of executing shells.

$ source test.sh
 $ . test.sh

Other operating methods:

sh test.sh
 dash test.sh
 zsh test.sh
 ...

For more related tutorials, please pay attention to PHP Chinese website!

The above is the detailed content of how shell scripts run in Linux. For more, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-to-run-shell-scripts-in-linux-linux-operation-and-maintenance/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索