代码拉取完成,页面将自动刷新
mypath="$HOME/tmp/tmpfj"
current_pid=$$
if [ ! -d "${mypath}" ]
then
mkdir "${mypath}"
fi
parent_id=$(ps -o pid,ppid,comm | grep $current_pid | awk -v current_pid_var=$current_pid '$1==current_pid_var{print $2}')
if [ ! -f "$mypath/$parent_id" ]
then
touch "$mypath/$parent_id"
fi
filetype=""
if [[ $# -ge 2 && "$2" != "-" ]];
then
filetype="*.$2"
fi
filepath="*"
path1="."
if [ $# -ge 3 ];
then
filepath="$3/*"
path1="$3"
fi
if [ "$filetype" = "" ];
then
grep -rn -E "$1" $filepath|\
awk 'BEGIN{FS=":";count=1}
{printf("[%d]: %s:%d:",count,$1, $2);
for (i=3; i<=NF;i++) printf("%s",$i)
print "";count+=1;}' | tee "$mypath/$parent_id"
else
find $path1 -name "$filetype" -print | xargs grep -nE "$1" \
| awk 'BEGIN{FS=":";count=1}
{printf("[%d]: %s:%d:",count,$1, $2);
for (i=3; i<=NF;i++) printf("%s",$i)
print "";count+=1;}' | tee "$mypath/$parent_id"
fi
cnt=$(awk 'END{print FNR}' "$mypath/$parent_id")
if [ $cnt -eq 0 ]
then
echo "******** / ^_^ \ |__| / ^_^ \\ ********"
exit -1
fi
num=""
read num?"输入查询的数字:"
if [[ $num == "" || $num == "\n" ]]
then
exit -1
fi
testnum=$(echo "$num" | grep [^0-9])
if [ "$testnum" == "" ]
then
fn "$num" "$parent_id"
else
echo "请输入正确的数字"
#read num
#testnum=$(echo "$num" | grep [^0-9])
# if [ "$testnum" == "" ]
# then
# fn "$num" "$parent_id"
# else
# echo "请输入正确的数字,不给你机会了!"
# exit -1
# fi
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。