Search script

xiaoxiao2021-03-06  14

#! / bin / bashset -o noglobusage () {echo "Usage: search [-e] [-f] regex [files] [Directory]" echo "-e: use extended regular expression" echo "-f: display full Path "Echo" default files to find is / "* /" "echo" default starting directory is /"./ "}

CMD_FILE = / Tmp / .searh. $ User.cmdoutput_file = / tmp / .search. $ User.log

FLAG_EGREP = flag_fullpath =

CMDLINE = $ (BaseName $ 0) "$ @" args = $ (getopt -q -u -o "efh" - "$ @") SET - $ args

FOR IDO CASE "$ I" in -e) flag_egrep = '- e'; shift ;; -f) flag_fullpath = 'y'; shift ;; -o) echo oarg is "" $ 2 "" "; oarg =" $ 2 "; shift; shift ;; - h) usage; exit 0 ;; -) shift; break ;; esacdone

REG_EXP = $ 1FILES = $ 2Start_Dir = $ 3

## Display the lastest search resultif [-z "$ reg_exp"]; the echo -ne "eXcuting" CAT $ cmd_file 2> / dev / null cat $ OUTPUT_FILE 2> / dev / null exit 0fi

Echo "$ CMDLINE"> $ cmd_file

[-z "$ start_dir"] && start_dir = '.' IF ["$ flag_fullpath" = "y"]; the start_dir = $ (cd $ start_dir; pwd) Fi [-z "$ files"] && files = " /. "" "$ start_DIR" -Regex "$ start_dir / $ files" -xdev -type f -follow -exec grep $ flag_egrep -i -l "$ reg_exp" {} /; 2> / dev / null | TEE $ OTPUT_FILE

EXIT $?

转载请注明原文地址:https://www.9cbs.com/read-50783.html

New Post(0)