ex45a.sh

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

SH
44
字号
#!/bin/bashechoecho "String operations using \"expr \$string : \" construct"echo "==================================================="echoa=1234zipper5FLIPPER43231echo "The string being operated upon is \"`expr "$a" : '\(.*\)'`\"."#     Escaped parentheses grouping operator.            ==  ==#       ***************************#+          Escaped parentheses#+           match a substring#       ***************************#  If no escaped parentheses...#+ then 'expr' converts the string operand to an integer.echo "Length of \"$a\" is `expr "$a" : '.*'`."   # Length of stringecho "Number of digits at the beginning of \"$a\" is `expr "$a" : '[0-9]*'`."# ------------------------------------------------------------------------- #echoecho "The digits at the beginning of \"$a\" are `expr "$a" : '\([0-9]*\)'`."#                                                             ==      ==echo "The first 7 characters of \"$a\" are `expr "$a" : '\(.......\)'`."#         =====                                          ==       ==# Again, escaped parentheses force a substring match.#echo "The last 7 characters of \"$a\" are `expr "$a" : '.*\(.......\)'`."#         ====                  end of string operator  ^^#  (actually means skip over one or more of any characters until specified#+  substring)echoexit 0

⌨️ 快捷键说明

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