read-novar.sh

来自「Shall高级编程」· Shell 代码 · 共 50 行

SH
50
字号
#!/bin/bash# read-novar.shecho# -------------------------- #echo -n "Enter a value: "read varecho "\"var\" = "$var""# Everything as expected here.# -------------------------- #echo# ------------------------------------------------------------------- #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.# ------------------------------------------------------------------- #echoecho "========================="echo#  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.# ================================================================= ##  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.  } <$0echo "Line 2 of this script is:"echo "$line2"   #   # read-novar.shecho            #   #!/bin/bash  line discarded.# See also the soundcard-on.sh script.exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?