gcc version filtering !!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gcc version filtering !!
# 1  
Old 06-26-2002
gcc version filtering !!

Folks,
I am using gcc 2.7.2.1 for NeXT PDO on my Solaris box. I want to get gcc version in a script. I do gcc -v and try to filter the output through awk. It won't come. Strange. Assigning it to the variable is also not possible. Any ideas ?

Cheers,
Amol.
# 2  
Old 06-26-2002
You are getting output as follows:

% set dummy=`date`
% echo $dummy
Wed Jun 26 14:01:50 EDT 2002
% set dummy=`gcc -v`
Reading specs from /u/lib/gcc-lib/sparc-sun-solaris2.6/2.8.1/specs
gcc version 2.8.1
% echo $dummy
%

This is because in the program it is sending output to standard error. The following shows this:

% set dummy=`gcc -v|& awk '{print $3}'`
% echo $dummy
from 2.8.1
%
Note that it put the third field from each line into the variable dummy.

I know I probably should have shown this from a sh or ksh, but I leave it to you to do some research. It will probably work the same way - the |& tells it to send both standard output and standard error to the next command. I also leave the clean up of what you are trying to grab out of there to you - post back if you are having problems.
# 3  
Old 06-27-2002
Well thanks. It works in csh..but I am writing script in sh.

I guess, & after | takes sh in background or something, it won't return to prompt if I try to set variable there.

However bash does not expect & to be there. It throws :

bash: command substitution: line 1: syntax error near unexpected token `&'
bash: command substitution: line 1: `gcc -v |& awk '{print $3 }''

Isn't there other way in sh/bash to capture output to std error ?
# 4  
Old 06-27-2002
Okay, since |& doesn't work in the other shell's, here's a hint. In your root crontab (root normally has sh as it's default shell) have you ever seen 2>&1?
# 5  
Old 06-28-2002
Computer

Yeah,

gcc -v 2>&1 | tail -1 | awk '{print $3}'

Thanks !! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Downloading and installing a very old version of gcc

I would like to acquire a very old version of gcc: 4.4.3 and set it up in such a way that I can use the update-alternatives command to switch between my current version and the older version. I believe I may have found a website where I can download 4.4.3 from. However, I am not sure what all I... (6 Replies)
Discussion started by: Circuits
6 Replies

2. Shell Programming and Scripting

Copy a file from directroy/ prior version to the directory/ new version

How to copy a file from directroy/ prior version to the directory/ new version automatically. (4 Replies)
Discussion started by: roy1912
4 Replies

3. Shell Programming and Scripting

Filtering out duplicates with the highest version number

Hi, I have a huge text file with filenames which which looks like the following ie uniquenumber_version_filename: e.g. 1234_1_xxxx 1234_2_vfvfdbb 343333_1_vfvfdvd 2222222_1_ggggg 55555_1_xxxxxx 55555_2_vrbgbgg 55555_3_grgrbr What I need to do is examine the file, look for... (4 Replies)
Discussion started by: mantis
4 Replies

4. Programming

Getting the random failure after upgraded the gcc version 3.1 to 3.4.6

I am getting the a random failure after upgrading the gcc version 3.1 to 3.4.6. My code where it is failing contains some STL and shared memory concepts.It is perfectly working on old version of gcc.I want to know what are possible causes that made this random error after upgrading gcc 3.4.6. (2 Replies)
Discussion started by: kapilkumawat
2 Replies

5. Solaris

Installing gcc - recieve error message gcc : cannot execute

AIM- Install Oracle 11g on Solaris using VMWare Steps 1.Logged on as root 2.Created subfolders à /usr/local/bin & /usr/local/bin/gcc 3.Downloaded gcc & libiconv & unzipped them on my harddrive & burnt them on CD 4.Copied files from CD to /usr/local/bin/gcc 5.Terminal (root) à pkgadd -d... (8 Replies)
Discussion started by: Ackers
8 Replies

6. Red Hat

GCC version problem

I have a host PC and a target system . Host System -> gcc (3.2) Redhat linux kernel 2.4.20-8 , glibc 2.3 Target System -> gcc (4.1) Fedora linux kernel 2.6.18-1.2798.fc6, glibc 2.5 I would like to build test program that can be run on both systems --------------------------- ... (0 Replies)
Discussion started by: mugdha
0 Replies

7. HP-UX

GCC version findout

Hi, In unix box GCC installed under the /usr/local/bin/gcc, i want to know the version of GCC. Could you please let me know the process for that. Thanks & Regards, Suji (1 Reply)
Discussion started by: srujana
1 Replies

8. UNIX for Dummies Questions & Answers

how to know the gcc version

Please someone can say me how to know the gcc version installed on my sunsolaris? Thanks (2 Replies)
Discussion started by: Minguccio75
2 Replies

9. Solaris

gcc output size differs on same version of solaris

Hello everybody, I am having two machines. I am using g++v2.95 When I do the build,the size of output file on both machines differ. I am not able to find what can be the problem. Both the machines are solaris 5.6 The command is : g++ -c -g -I./ -I../../../include -I/usr/local/include/g++-3... (1 Reply)
Discussion started by: manishs13
1 Replies

10. UNIX for Dummies Questions & Answers

gcc compiler version?

How do you determine which version of the GNU gcc compiler is on your system? (1 Reply)
Discussion started by: Ben070371
1 Replies
Login or Register to Ask a Question