Results 1 to 4 of 4
Hi,
I have written a bash script to compile multiple programs. The script runs a loop and at a certain point calls the compiler. However as soon as the first ...
- 04-08-2011 #1Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
Need help with bash script looping
Hi,
I have written a bash script to compile multiple programs. The script runs a loop and at a certain point calls the compiler. However as soon as the first compilation fails, it exits the loop. What I want is, the compilation failure should be informed (written in an error file) but the script should complete all compilations.
If I remove the erroneous program, the loop completes. However as soon as a compilation error occurs, the script exits.
Someone please help.
Regards,
AlokLast edited by khandaa; 04-08-2011 at 09:43 AM. Reason: typing mistakes
- 04-08-2011 #2Linux Newbie
- Join Date
- Nov 2008
- Location
- Tokyo, Japan
- Posts
- 243
Is your script Bash, or GNU Make?
Which programming language are you using?
Which compiler are you using?
I'd like to see some example code to better understand your problem.
Here is how I would write a compile loop using Bash.Code:#!/bin/bash cd my/source/directory # Assuming "$EXT" is a variable with the value set to # the file extension of the source code you want to compile, # for example: "c", "py", or "ml". for CODE_FILE in *".$EXT" do ERROR_FILE=${CODE_FILE%%"$EXT"}.error if compile $CODE_FILE 2>$ERROR_FILE then rm -f $ERROR_FILE else echo "Compiling \"$CODE_FILE\" failed:"; cat $ERROR_FILE fi done
- 04-08-2011 #3
Hi there,
I have had this type of trouble before building RPMs. My solution was the following, although other people may have better ideas:
This let the build script I was writing continue when something broke, I hope it helps!Code:command || /bin/true
- 04-08-2011 #4Just Joined!
- Join Date
- Apr 2011
- Posts
- 3
Need help with bash script looping
Hello Ramin and Ziplock,
Thanks for your feedback. I tried both options and the one suggested by Ziplock worked. Your help has been a lifesaver for me. Thankyou very much.
btw, Ramin, my script is bash script, programming language is C and compiler gcc.
regards,
Alok


Reply With Quote