bin-grep.sh
来自「Shall高级编程」· Shell 代码 · 共 40 行
SH
40 行
#!/bin/bash# bin-grep.sh: Locates matching strings in a binary file.# A "grep" replacement for binary files.# Similar effect to "grep -a"E_BADARGS=65E_NOFILE=66if [ $# -ne 2 ]then echo "Usage: `basename $0` search_string filename" exit $E_BADARGSfiif [ ! -f "$2" ]then echo "File \"$2\" does not exist." exit $E_NOFILEfi IFS=$'\012' # Per suggestion of Anton Filippov. # was: IFS="\n"for word in $( strings "$2" | grep "$1" )# The "strings" command lists strings in binary files.# Output then piped to "grep", which tests for desired string.do echo $worddone# As S.C. points out, lines 23 - 30 could be replaced with the simpler# strings "$2" | grep "$1" | tr -s "$IFS" '[\n*]'# Try something like "./bin-grep.sh mem /bin/ls"#+ to exercise this script.exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?