Compiling multiple ".c" files starting with xxx


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compiling multiple ".c" files starting with xxx
# 1  
Old 03-03-2010
Compiling multiple ".c" files starting with xxx

Hello,

I am trying to figure out how I can write a bashscript that compiles several ".c" files that start with xxx (example: xxx_try.c and xxx_that.c)
So I want to compile all these files with a bash script. Anyone can help pls?
# 2  
Old 03-03-2010
Code:
#!/bin/sh

exec gcc abc_*.c -O myexec

# 3  
Old 03-03-2010
Does this compiles all the files in 1 file?
I need to compile them all seperatly (prefered)
So if I have files xxx_sss.c and xxx_bbb.c I need to compile them in 1 bash script but it has to make 2 different files
# 4  
Old 03-03-2010
Did you try before you ask question again?
# 5  
Old 03-04-2010
MySQL

Just have a loop through the files and compile it using with the -o option in cc.There while you can get the executable file for each file.

Code:
for file in `ls abc_*.c`
do
        cc -o "$file.execute" $file
done

"abc" is the similarity between the files.And I created the executable file with the .execute extension.If the file name is abc_1.c then the executable file will get create by the name abc_1.execute.

Thanks
# 6  
Old 03-04-2010
Thx, this is what I was looking for
# 7  
Old 03-04-2010
Quote:
Originally Posted by karthigayan
Just have a loop through the files and compile it using with the -o option in cc.There while you can get the executable file for each file.

Code:
for file in `ls abc_*.c`
do
        cc -o "$file.execute" $file
done

"abc" is the similarity between the files.And I created the executable file with the .execute extension.If the file name is abc_1.c then the executable file will get create by the name abc_1.execute.

Thanks
This is a combo Useless Use of ls * and Useless Use of Backticks. A version that doesn't process the list in triplicate:
Code:
for file in abc_*.c
do
        cc -o "${file}.execute" "${file}"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

2. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. AIX

"fuser -c -k /XXX/XXXXXXX" Fails and stuck on AIX 6100-05-01-1016

Hi I was wondering if anybody has come across in a failure of fuser command. We have a backup script that is: fuser -c -k /XXX/XXXXXXX sync;sync umount /XXX/XXXXXXX/ backup -0 -f /dev/rmt0.1 -u /dev/XXXXXXXlv mount /XXX/XXXXXXX/ sync;sync The script is called from crontab via an... (2 Replies)
Discussion started by: ggovotsis
2 Replies

5. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

6. Shell Programming and Scripting

Script for delete tmp files older than 15 days and owned by "xxx" id

Hi All , I want to delete files from /tmp directory created by "xxxx" id. because i got the list says more than 60 thousand files were created by "xxxx" id since 2002. The /tmp directory has lot of files created by different user ids like root,system etc.. But, i need a script to... (2 Replies)
Discussion started by: vparunkumar
2 Replies

7. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

8. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

9. HP-UX

ld: (Warning) Symbol "XXX" is not exported but is imported by a shared

Hi, I am trying to build the package for my build tree built with HP UX ecom compiler. I added the flags +check=all to enable run time checks. I compile the tree successfully, but while making the packages I am getting following error: === vxms tests = Generating pgncpio ld: (Warning)... (5 Replies)
Discussion started by: prits31
5 Replies

10. UNIX for Dummies Questions & Answers

get two strings ending with "." and starting with "."

Hi all, In unix shell, I want to get two strings ending with "." and starting with "." from a string "chan.txt" For example, a string "chan.txt". The first string is "chan" The second string is "txt" Yours Wilson (1 Reply)
Discussion started by: wilsonchan1000
1 Replies
Login or Register to Ask a Question