Shell variables can be directly assigned to a value or script, you can also use the Read command to get read as built-in commands from a standard loser help read view
[Syntax format]
Read "parameter" "Variable name"
"Common parameters"
-P Prompt: setting prompt information
-T timeout: Sets the time for input waits, in seconds by default
Sample 1:read Basic Read-in
[Email protected] ~]# read-p "Please input number:" A1 a2please input "Number:12 13[[email protected] ~]# echo $a 112[[email protected] ~]# echo $a 213
Tip: The above read-p functions can be implemented with ECHO and read
Actual combat:
Change the subtraction calculation script to read into the integer variable by reading
#!bin/bashread-t 10-p "input number" a Becho "$a-$b =$ (($a-$b))" echo "$a + $b =$ (($a + $b))" echo "$a * $b =$ (($a * $b))" Echo "$a/$b =$ (($a/$b))" echo "$a * * $b =$ (($a * * $b))" [[Email protected] ~]# sh read.sh input number2 62-6=-42+6=82*6=122/6=02 **6=64
This article is from the "Little Rookie" blog, please be sure to keep this source http://baishuchao.blog.51cto.com/12918589/1941078
Shell variable input read explain and combat