8 Star 21 Fork 5

hotmocha/minitalk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
fu 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
hotmocha 提交于 2016-02-02 14:18 . add some shell
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/hotmocha/minitalk.git
git@gitee.com:hotmocha/minitalk.git
hotmocha
minitalk
minitalk
master

搜索帮助