We know that there are two ways to receive incoming parameters in Shell. One is to pass parameters through the script, and the other is to receive the incoming parameters through read. A simple example of passing parameters through a script is as follows: # Pass through the script, where $0 refers to the script name, $1 is the first parameter, and $2 is the second parameter [root@host ~]# ./script.sh 1 2 Total = 3 [root@host ~]# vim script.sh #!/bin/bash function add() { total=$(expr $1 + $2) echo -e "Total = $total" } add $1 $2 Let's look at receiving the incoming parameters through read. First, look at the basic format of read:
[root@host ~]# ./script.sh Enter Password: The password your input is: Test@1234\ [root@host ~]# vim script.sh #!/bin/bash read -n10 -t30 -r -s -d $ -p "Enter Password:" password echo -e "\nThe password your input is:$password"
From the above example, most of the common functions above are basically covered, especially the -p, -n, -t, -s and other parameters, which can be used to learn the read command well. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: How to create WeChat games with CocosCreator
>>: Solution to Chinese garbled characters when operating MySQL database in CMD
Use vite to build a vue3 project You can quickly ...
Tutorial Series MySQL series: Basic concepts of M...
Mysql is a popular and easy-to-use database softw...
The Docker package is already included in the def...
The detailed process of installing python3.7.0 on...
React Hooks is a new feature introduced in React ...
1. Download MySQL database and install and config...
This article example shares the specific code for...
Table of contents The role of cloneElement Usage ...
The previous article on Docker mentioned the cons...
As a tester, you may often need to install some s...
Today I have a question about configuring MySQL d...
MySQL download and installation (version 8.0.20) ...
Table of contents Preface 1. Routing lazy loading...
Achieve results Implementation Code html <div ...