grp.sh

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

SH
35
字号
#!/bin/bash# grp.sh: Very crude reimplementation of 'grep'.E_BADARGS=65if [ -z "$1" ]    # Check for argument to script.then  echo "Usage: `basename $0` pattern"  exit $E_BADARGSfi  echofor file in *     # Traverse all files in $PWD.do  output=$(sed -n /"$1"/p $file)  # Command substitution.  if [ ! -z "$output" ]           # What happens if "$output" is not quoted?  then    echo -n "$file: "    echo $output  fi              #  sed -ne "/$1/s|^|${file}: |p"  is equivalent to above.  echodone  echoexit 0# Exercises:# ---------# 1) Add newlines to output, if more than one match in any given file.# 2) Add features.

⌨️ 快捷键说明

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