Debian Codegraph @

read-novar.sh

raw symbols SCIP
1 #!/bin/bash
2 # read-novar.sh
3
4 echo
5
6 # -------------------------- #
7 echo -n "Enter a value: "
8 read var
9 echo "\"var\" = "$var""
10 # Everything as expected here.
11 # -------------------------- #
12
13 echo
14
15 # ------------------------------------------------------------------- #
16 echo -n "Enter another value: "
17 read # No variable supplied for 'read', therefore...
18 #+ Input to 'read' assigned to default variable, $REPLY.
19 var="$REPLY"
20 echo "\"var\" = "$var""
21 # This is equivalent to the first code block.
22 # ------------------------------------------------------------------- #
23
24 echo
25 echo "========================="
26 echo
27
28
29 # This example is similar to the "reply.sh" script.
30 # However, this one shows that $REPLY is available
31 #+ even after a 'read' to a variable in the conventional way.
32
33
34 # ================================================================= #
35
36 # In some instances, you might wish to discard the first value read.
37 # In such cases, simply ignore the $REPLY variable.
38
39 { # Code block.
40 read # Line 1, to be discarded.
41 read line2 # Line 2, saved in variable.
42 } <$0
43 echo "Line 2 of this script is:"
44 echo "$line2" # # read-novar.sh
45 echo # #!/bin/bash line discarded.
46
47 # See also the soundcard-on.sh script.
48
49 exit 0