Skip to content

Commit

Permalink
improve find-in-jars.sh, output progress message when interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Sep 3, 2017
1 parent 1fc953c commit c49aa83
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions find-in-jars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,19 @@ clear_line_if_is_console() {
}


find "${dirs[@]}" -iname '*.jar' | while read jarFile; do
readonly jar_files="$(find "${dirs[@]}" -iname '*.jar')"
readonly total_count="$(echo "$jar_files" | wc -l)"

$is_console && echo -n "finding in jar: $jarFile"
counter=1
while read jar_file; do
$is_console && echo -n "finding in jar($((counter++))/$total_count): $jar_file"

jar tf "${jarFile}" | grep -E "$pattern" | while read file; do
jar tf "${jar_file}" | grep -E "$pattern" | while read file; do
clear_line_if_is_console

echo "${jarFile}"\!"${file}"
echo "${jar_file}"\!"${file}"
done

clear_line_if_is_console
done

done < <(echo "$jar_files")

6 comments on commit c49aa83

@kaojunsong
Copy link

@kaojunsong kaojunsong commented on c49aa83 Nov 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后一行done < <(echo "$jar_files") 执行的时候报错:

find-in-jars.sh: line 177: syntax error near unexpected token `<'
find-in-jars.sh: line 177: `done < <(echo "$jar_files")'

@oldratlee
Copy link
Owner Author

@oldratlee oldratlee commented on c49aa83 Nov 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaojunsong 有可能是 比如bash的版本不兼容。给一下你的环境信息,就像这样:

# 注意! 要是你执行脚本的Bash!
$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

$ uname -a
Darwin typechecker.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64 i386 MacBookPro11,2 Darwin

@kaojunsong
Copy link

@kaojunsong kaojunsong commented on c49aa83 Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ /bin/bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ uname -a
Linux tjtxvm-184-3.58os.org 2.6.32-504.23.4.el6.x86_64 #1 SMP Tue Jun 9 20:57:37 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

@oldratlee
Copy link
Owner Author

@oldratlee oldratlee commented on c49aa83 Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaojunsong 你的bash已经是4了

确认是最新的实现 https://github.com/oldratlee/useful-scripts/blob/master/find-in-jars

用debug方式运行一下 😄

/bin/bash -x find-in-jars

贴一下运行输出

@kaojunsong
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oldratlee 感谢你的耐心回复!
问题原因找到了,我执行你的脚本用的是sh find-in-jars.sh,刚刚了解了下,/bin/sh和/bin/bash存在一些小的差别,使用/bin/bash可以正常运行了,再次感谢

@oldratlee
Copy link
Owner Author

@oldratlee oldratlee commented on c49aa83 Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaojunsong OK,问题解决就好~ 😄

PS:

尽量不要自己指定执行的Shell❗️ 不好的实践。
(这也是我把文件的后缀sh去掉的原因,尽量引导以避免有这样习惯的人这样操作。)

更多说明如下:

image

#57 (comment)

Please sign in to comment.