linux USES the read command to get the values in a variable

  • 2020-06-23 02:18:58
  • OfStack

preface

This article mainly introduces linux's use of read command to get the median value of variables related content, share for your reference and learning, the following words are not enough, let's have a look at the detailed introduction.

Common USES of read are as follows:


read -[pstnd] var1 var2 ...
-p prompt statement - Number of n characters -s shielded echo -ES14en wait time -ES15en input boundary

read gets variables from the screen, waiting for user input. How do you get values from known variables using the read command?

For example: input_ips='127.127.127.10-127.127.127.14', read to start_ip and end_ip by read command, respectively?

Method 1:


root@linux~# input_ips='127.127.127.10-127.127.127.14' 
root@linux~# read start_ip end_ip < <(echo $input_ips | awk -F'-' '{print $1, $2}') 
root@linux~# echo -e "START_IP=$start_ip; END_IP=$end_ip" 
START_IP=127.127.127.10; END_IP=127.127.127.14 

Method 2:


root@linux~# input_ips='127.127.127.10-127.127.127.14' 
root@linux~# read start_ip end_ip <<-EOF 
> `echo $input_ips | awk -F'-' '{print $1, $2}'` 
> EOF 
root@linux~# echo -e "START_IP=$start_ip; END_IP=$end_ip" 
START_IP=127.127.127.10; END_IP=127.127.127.14 

conclusion


Related articles: