📄 grp.sh
字号:
#!/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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -