echo-params.sh

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

SH
40
字号
#!/bin/bash# echo-params.sh# Call this script with a few command line parameters.# For example:#     sh echo-params.sh first second third fourth fifthparams=$#              # Number of command-line parameters.param=1                # Start at first command-line param.while [ "$param" -le "$params" ]do  echo -n "Command line parameter "  echo -n \$$param     #  Gives only the *name* of variable.#         ^^^          #  $1, $2, $3, etc.                       #  Why?                       #  \$ escapes the first "$"                       #+ so it echoes literally,                       #+ and $param dereferences "$param" . . .                       #+ . . . as expected.  echo -n " = "  eval echo \$$param   #  Gives the *value* of variable.# ^^^^      ^^^        #  The "eval" forces the *evaluation*                       #+ of \$$                       #+ as an indirect variable reference.(( param ++ ))         # On to the next.doneexit $?# =================================================$ sh echo-params.sh first second third fourth fifthCommand line parameter $1 = firstCommand line parameter $2 = secondCommand line parameter $3 = thirdCommand line parameter $4 = fourthCommand line parameter $5 = fifth

⌨️ 快捷键说明

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