col-totaler2.sh
来自「Shall高级编程」· Shell 代码 · 共 45 行
SH
45 行
#!/bin/bash# Another version of the "column totaler" script#+ that adds up a specified column (of numbers) in the target file.# This one uses indirect references.ARGS=2E_WRONGARGS=65if [ $# -ne "$ARGS" ] # Check for proper no. of command line args.then echo "Usage: `basename $0` filename column-number" exit $E_WRONGARGSfifilename=$1column_number=$2#===== Same as original script, up to this point =====## A multi-line awk script is invoked by awk ' ..... '# Begin awk script.# ------------------------------------------------awk "{ total += \$${column_number} # indirect reference}END { print total } " "$filename"# ------------------------------------------------# End awk script.# Indirect variable reference avoids the hassles#+ of referencing a shell variable within the embedded awk script.# Thanks, Stephane Chazelas.exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?