Read interaction [[[email protected] shell-test]# vim read.sh[[email protected] shell-test]# vim read.sh[[email Protected] shell-test]# lltotal 52-rw-r--r--1 root root 0 Jul 00:52 012-rw-r--r--1 root root 201 Jul 19:04 2-r w-r--r--1 root root 0 Jul 00:45 abc-rwxr-xr-x 1 root root 163 Jul 19:16 echotest1.sh-rwxr-xr-x 1 root root 183 Jul 19:24 echotest2.sh-rwxr-xr-x 1 root root 149 Jul 03:15 echotest.sh-rwxr-xr-x 1 root root 164 Jul 23:25 Hel Lo.sh-rwxr-xr-x 1 root root 157 Jul 00:28 h.tx-rwxr-xr-x 1 root root 201 Jul 19:04 para.sh-rw-r--r--1 root root 539 Jul 19:47 read.sh-rwxr-xr-x 1 root root 118 Jul 02:52 sum.shdrwxr-xr-x 2 root root 4096 Jul 00:01 test-rwxr- Xr-x 1 root root 02:37 test$.sh-rw-r--r--1 root root 7283 Jul 02:20 vari.txt[[email protected] shell- test]# chmod a+x read.sh[[email protected] shell-test]# lltotal 52-rw-r--r--1 root root 0 Jul 00:52 012-rw-r-- r--1 root root 201 Jul 14 19:04 2-rw-r--r--1 root root 0 Jul 00:45 abc-rwxr-xr-x 1 root root 163 Jul 19:16 echotest1.sh-rwxr-xr-x 1 root R Oot 183 Jul 19:24 echotest2.sh-rwxr-xr-x 1 root root 149 Jul 03:15 echotest.sh-rwxr-xr-x 1 root root 164 Jul 13 2 3:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 00:28 h.tx-rwxr-xr-x 1 root root 201 Jul 19:04 para.sh-rwxr-xr-x 1 roo T root 539 Jul 19:47 read.sh-rwxr-xr-x 1 root root 118 Jul 02:52 sum.shdrwxr-xr-x 2 root root 4096 Jul 00:01 te St-rwxr-xr-x 1 root root 02:37 test$.sh-rw-r--r--1 root root 7283 Jul 02:20 vari.txt[[email protected ] shell-test]# sh read.shPleaseread.sh:line 3:read: ' Name: ': Not a valid IdentifierName Isplease enter your age:nage is Please select your gender[m/f]: nsex is[[email protected] shell-test]# cat read.sh#!/bin/bash# Author:shenchao (E-m AIL: [email protected]) read-t 30-p Please input your name:name# prompt "Enter name" and wait 30 seconds to save the user's input into the variable name Echo name is $name Read-s-T 30-p "please Enter your age: "age# ages is privacy, so we use the"-S "option to hide the input echo-e \necho is $age read-n 1-t 30-p" Please select your gender[m/f]: "gender# Use the"-N 1 "option to receive only one input character will be executed (without entering enter) Echo-e \necho Sex is $gender [[email protected] shell-test]# CP read.sh REA d1.sh [[email protected] shell-test]# lltotal 56-rw-r--r--1 root root 0 Jul 00:52 012-rw-r--r--1 root root 2 Jul 19:04 2-rw-r--r--1 root root 0 Jul 00:45 abc-rwxr-xr-x 1 root root 163 Jul 19:16 ECHOTEST1.SH-RWXR-XR -X 1 root root 183 Jul 19:24 echotest2.sh-rwxr-xr-x 1 root root 149 Jul 03:15 echotest.sh-rwxr-xr-x 1 root root 1 Jul 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 00:28 h.tx-rwxr-xr-x 1 root root 201 Jul 19:04 PARA.SH-RWXR -xr-x 1 root root 539 Jul 19:50 read1.sh-rwxr-xr-x 1 root root 539 Jul 19:47 read.sh-rwxr-xr-x 1 root root 118 Ju L 02:52 sum.shdrwxr-xr-x 2 root root 4096 Jul 00:01 test-rwxr-xr-x 1 root root--Jul 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 1402:20 vari.txt[[email protected] shell-test]# vim read1.sh[[email protected] shell-test]# sh read1.sh please Input your name:name isplease Enter your age:nage isplease Select your gender[m/f]: nsex is[[email protected] shell- The test]# cat read1.sh #!/bin/bash#-P option defaults to a space-matching prompt, and if the hint is longer, a space needs to be quoted. Read-t 30-p "Please input your name:" name# Prompt "lose Name "and wait 30 seconds for the user's input to be saved into the variable name Echo name is $name read-s-t 30-p" Please enter your Age: "age# ages is privacy, so we use the"-S "option to hide the input echo-e \necho Age was $age read-n 1-t 30-p "Please select your gender[m/f]:" gender# Use the "-N 1" option to receive only one input character will be executed (without entering the carriage) ECHO-E \ n Echo Sex is $gender [[[email protected] shell-test]# vim read1.sh[[email protected] shell-test]# sh read1.sh Please input your name:name isplease Enter your age:nage isplease Select your gender[m/f]: Sex is[[email protected] The shell-test]# cat read1.sh #!/bin/bash#-P option defaults to a space-matching prompt, and if the hint is longer there are spaces that need to be quoted. Read-t 30-p "Please input your name:" Name #提示 "Please enter a name" and wait 30 seconds to save the user's input into the variable nameIn Echo Name is $name read-s-t 30-p "Please enter your Age:" age# ages is privacy, so we use the "-S" option to hide the input echo-e \necho $age read-n 1-t 30-p "Please select your gender[m/f]:" gender# Use the "-N 1" option to receive only one input character will be executed (without entering enter) Echo-e "\ n" Echo Sex is $gender [[EMA Il protected] shell-test]# sh read1.sh Please input your name:lycname are lycplease enter your age:nage is 181818Plea SE Select your gender[m/f]: Msex is m[[email protected] shell-test]# [[email protected] shell-test]# sh read1.s H. Your name:lycname is lycplease enter your age:nage are 18Please select your gender[m/f]: Msex is M[[EMAIL&N Bsp;protected] shell-test]# cat read1.sh #!/bin/bash#-P option defaults to a space-matching prompt, and if the hint is longer, a space needs to be quoted. Read-t 30-p "please input yo ur name: "name# Prompt" Please enter the name "and wait 30 seconds to save the user's input into the variable name Echo name is $name read-s-t 30-p" pls enter your age: "age# ages is privacy, so We use the "-S" option to hide the input echo-e \necho age was $age read-n 1-t 30-p "Please select your gender[m/f]:" gender# using the "-N 1" option to receive only one input character will Execute (neither enter carriage) echo-e "\ n" ECHo Sex is $gender [[[email protected] shell-test]# vim read1.sh[[email protected] shell-test]# sh read1.sh Please input your name:lycname are lycplease enter your age:age is 20Please select your gender[m/f]: Msex is m[[email  ;p rotected] shell-test]# cat read1.sh #!/bin/bash#-P option defaults to a space-matching prompt, and if the hint is longer, a space needs to be quoted. Read-t 30-p "Please input your Name: "name# Prompt" Please enter the name "and wait 30 seconds, the user's input is saved into the variable name" echo name is $name read-s-t 30-p "pls enter your age:" age# ages is privacy, so we use The "-S" option hides the input echo-e "\ n" echo $age read-n 1-t 30-p "Please select your gender[m/f]:" gender# using the "-N 1" option to receive only one input character will Line (neither input carriage) echo-e "\ n" Echo Sex is $gender [[email protected] shell-test]#
Shell Read interaction