LDP/LDP/guide/docbook/abs-guide/read-novar.sh

50 lines
1.3 KiB
Bash
Raw Normal View History

2002-06-03 14:36:49 +00:00
#!/bin/bash
2004-04-28 12:08:07 +00:00
# read-novar.sh
2002-06-03 14:36:49 +00:00
echo
# -------------------------- #
echo -n "Enter a value: "
read var
echo "\"var\" = "$var""
# Everything as expected here.
# -------------------------- #
echo
2004-03-15 13:47:54 +00:00
# ------------------------------------------------------------------- #
2002-06-03 14:36:49 +00:00
echo -n "Enter another value: "
read # No variable supplied for 'read', therefore...
#+ Input to 'read' assigned to default variable, $REPLY.
var="$REPLY"
echo "\"var\" = "$var""
# This is equivalent to the first code block.
2004-03-15 13:47:54 +00:00
# ------------------------------------------------------------------- #
2002-06-03 14:36:49 +00:00
echo
2007-04-26 21:13:49 +00:00
echo "========================="
echo
2002-06-03 14:36:49 +00:00
2006-06-22 14:28:13 +00:00
# This example is similar to the "reply.sh" script.
# However, this one shows that $REPLY is available
#+ even after a 'read' to a variable in the conventional way.
2007-04-26 21:13:49 +00:00
# ================================================================= #
# In some instances, you might wish to discard the first value read.
# In such cases, simply ignore the $REPLY variable.
{ # Code block.
read # Line 1, to be discarded.
read line2 # Line 2, saved in variable.
} <$0
2007-04-26 21:13:49 +00:00
echo "Line 2 of this script is:"
echo "$line2" # # read-novar.sh
echo # #!/bin/bash line discarded.
# See also the soundcard-on.sh script.
exit 0