$ 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!