ex60.sh

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

SH
56
字号
#!/bin/bash# Functions and parametersDEFAULT=default                             # Default param value.func2 () {   if [ -z "$1" ]                           # Is parameter #1 zero length?   then     echo "-Parameter #1 is zero length.-"  # Or no parameter passed.   else     echo "-Param #1 is \"$1\".-"   fi   variable=${1-$DEFAULT}                   #  What does   echo "variable = $variable"              #+ parameter substitution show?                                            #  ---------------------------                                            #  It distinguishes between                                            #+ no param and a null param.   if [ "$2" ]   then     echo "-Parameter #2 is \"$2\".-"   fi   return 0}echo   echo "Nothing passed."   func2                          # Called with no paramsechoecho "Zero-length parameter passed."func2 ""                       # Called with zero-length paramechoecho "Null parameter passed."func2 "$uninitialized_param"   # Called with uninitialized paramechoecho "One parameter passed."   func2 first           # Called with one paramechoecho "Two parameters passed."   func2 first second    # Called with two paramsechoecho "\"\" \"second\" passed."func2 "" second       # Called with zero-length first parameterecho                  # and ASCII string as a second one.exit 0

⌨️ 快捷键说明

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