sh/bash -- find all files with the word java in them

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

sh/bash -- find all files with the word java in them

#1 Post by s243a »

This is my first attempt at a bash or an sh script

Code: Select all

for aFile in `find /etc`; do
  found=0
  #echo "Entering $aFile"
  for line in `grep '^.*java.*$' -i -x $aFile`; do
    if [ $found -eq 0 ]; then
       echo "File = $aFile"
      let found=1
    fi
    #echo "Line = $line"
  done
done
here is the output:

Code: Select all

File = /etc/hosts
grep: /etc/xdg/menus/applications-merged/The: No such file or directory
grep: Free: No such file or directory
grep: Network: No such file or directory
grep: Project.menu: No such file or directory
File = /etc/mime.types
grep: /etc/init.d/binfmt-support: No such file or directory
File = /etc/modprobe.d/puppy.conf
File = /etc/hiawatha/mimetype.conf
File = /etc/gitweb.conf
File = /etc/X11/xkb/symbols/pc/in
File = /etc/services
**Notes
1. I couldn't figure out how to use the variables true and fase so I used one and zero instead.
2. grep seems to give an error when passed a broken symbolic link. I need a way to suppress this.

If your curious why I wrote the script. I was wondering where the java library search path might be stored. My puppy version is "precise". I recently installed libsvn-java (i.e. javaHL) which is a library required for eclipse to import from a git repository. The puppy package manager installed this at:

/usr/lib/jni

This was not in the java search path as seen by eclipse. According to:
http://subclipse.tigris.org/wiki/JavaHL

I can tell eclipse where this is by including the following line in the eclipse.ini file:

Code: Select all

-Djava.library.path=/usr/lib/jni
However, if you want to include the locations within LD_LIBRARY_PATH as well then one should instead use:

Code: Select all

-Djava.library.path="${workspace_loc:project}\lib;${env_var:PATH}"
according to:
http://stackoverflow.com/questions/6613 ... instead-of

Therefore, I think I should have searched instead for "LD_LIBRARY_PATH". As for making perminant environmental variable changes

In another thread they suggested editing either "/etc/profile.local" or "/etc/profile.d/". Maybe I'll think about how to do this.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#2 Post by amigo »

Much, much, much faster and shorter:
grep '^.*java.*$' /etc/*

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#3 Post by MochiMoppel »

grep -rl java /etc/*

User avatar
Uten
Posts: 129
Joined: Tue 29 Jan 2008, 11:00

#4 Post by Uten »

Hi @s243a,
Congrats with a nice first attempt at a script. I suspect you have some knowledge in programing in another language so therefor I will just point you to som nice resources in shell/bash scripting.
http://www.grymoire.com/Unix/ Also take a look at the sed and awk section.
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.htmlBrows trough and easy lookup.
http://www.tldp.org/LDP/abs/html/index.html atleast if you include it in a search to find the right page.
I keep a copy of the two last ones on my lookal disk to do quick searches.

Best regards
Uten

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#5 Post by s243a »

Uten wrote:Hi @s243a,
Congrats with a nice first attempt at a script. I suspect you have some knowledge in programing in another language so therefor I will just point you to som nice resources in shell/bash scripting.
http://www.grymoire.com/Unix/ Also take a look at the sed and awk section.
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.htmlBrows trough and easy lookup.
http://www.tldp.org/LDP/abs/html/index.html atleast if you include it in a search to find the right page.
I keep a copy of the two last ones on my lookal disk to do quick searches.

Best regards
Uten
I just found today what looks like a great linux reference:
http://www.gnu.org/software/bash/manual ... -Expansion

Pelo

Pfind ?

#6 Post by Pelo »

Pfind ?
Attachments
java.png
.. for newbies, !
(70.05 KiB) Downloaded 143 times

Post Reply