Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a question about the following command:

apt-cache search java | awk '{print($1)}' | grep -E -e '^(ia32-)?(sun|oracle)-java' -e '^openjdk-' -e '^icedtea' -e '^(default|gcj)-j(re|dk)' -e '^gcj-(.*)-j(re|dk)' -e 'java-common'

Owing to my limited IT knowledge, am I right to say that the (ia32-) in the above command refers to 32-bit software? If it is, then I assume that the above command is for 32-bit installed OS.

However I installed a 64-bit OS.

What is the correct parameter for 64-bit software? Is it (amd64-) or (ia-64) or (x86_64-)?

Any expert help is much appreciated.

share|improve this question
1  
ia32- won't represent a 32 bit software.It also looks for the package name starting with ia32-.The only package that starts with ia32- is ia32-libs –  Avinash Raj Mar 24 at 14:37
1  
^- starting, ? - optional ,| - OR –  Avinash Raj Mar 24 at 14:44
    
@AvinashRaj: Thanks for your explanation. –  n00b Mar 24 at 16:01
1  
Note that the | means "OR" only within the regular expressions above, between the various commands it is a pipe. –  terdon Mar 24 at 16:04
    
@terdon: Noted with thanks. –  n00b Mar 24 at 16:05

1 Answer 1

up vote 6 down vote accepted

First of all, apt-cache search does not search for installed packages, it looks for available ones, both installed and not installed. Also, the various search patterns you see are not mutually exclusive, so lines matching any of them will be printed. Finally, the ? after ^(ia32-) means ia32- is optional, the expression will match lines that have it and lines that don't. So, your command will indeed work for 64 and 32 bit systems.

The equivalent command to look for installed packages only would be:

dpkg -l *java* | awk '{print($2)}' | 
    grep -E -e '^(ia32-)?(sun|oracle)-java' -e '^openjdk-' -e '^icedtea' \
      -e '^(default|gcj)-j(re|dk)' -e '^gcj-(.*)-j(re|dk)' -e 'java-common'

But don't use that. In Debian derived systems such as Ubuntu, there is a special tool for this, update-java-alternatives which, when run with the -l option will list installed Java environments:

 update-java-alternatives -l

On my system, for example, this prints:

java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
jdk-7-oracle-x64 317 /usr/lib/jvm/jdk-7-oracle-x64
share|improve this answer
    
Thanks for such your answer and detailed explanation. Is there a way for me to award you more points? –  n00b Mar 24 at 15:57
    
What programming language was the command written in? C? C++? Basic? C#? The whole command resembles a string of art with ^ | and * –  n00b Mar 24 at 16:00
    
@n00b if an answer solves your issue, you can mark it as accepted by clicking on the checkmark on the right. That will show others that this is the solution that helped you and has the pleasent side effect of giving me 15 rep points. No other thanks are needed :) –  terdon Mar 24 at 16:01
1  
The language is basic shell scripting and regular expressions. The ^ is a regular expression trick, it means match the beginning of a line, the | are pipes which pass the output of one command as input to another. * is a wildcard, it means 0 or more. –  terdon Mar 24 at 16:03
1  
No, it is a simple programming language but all the strange stuff you see here are regular expressions, the shell part is what pass the input of one command to another (using |). For a very nice tutorial on regular expressions, see here. –  terdon Mar 24 at 16:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.