scripting: How to check if configure or make fails?
Hi folks.
My first post over here at this place. I am a kind of newbie when it comes to advanced scripting and programming. I've written a script to install Alsa manually: http://ubuntuforums.org/showthread.p...18#post5792918 The problem is, if a "./configure" or "make" fails during the process, the whole installation gets corrupted. Within the script I want to check before running the "make install" for each package, if all of the "./configure" and "make" finished without error. What would be the best way to do this? THX for your support. KLSS |
./configure && make && make install
|
Do you know about the return code of commands?
It tells you if a command failed or succeeded. it's called $? from the shell For instance, let's do a simple command and see the return code: $ ls $ echo $? It will print the return code of ls, which is 0 if succeeded and something else if failed. you can use this code to take action: $ ls $ if [ "$?" -ne 0 ] > then > echo "Failed" > fi You can also use the || and && operators like this: $ ls || echo "Failed" $ make || exit 1 $ make && echo "success" |
Quote:
In a script people usually do something in the lines of this: Code:
function die() { The most basic version would work the same, just chaining them with && Code:
./configure && make && su -c 'make install' Code:
(./configure && make && su -c 'make install') || echo myerror && exit 1 |
Thx a lot folks.
I'll implement your suggestions. Just a question: Would it be possible to put the whole process also in a "while" loop? while true do? Just an idea. THX again. Klss |
indeed, do it like this:
while true do echo "I must do something here" [ $? -eq 0 ] || break done this will print 'I must do something here' indefinitely, until it fails, which should never happen anyway but... I don't get how you want to use it for configure and make and make install... |
Quote:
I just introduced above proposals to the Alsa upgrade script. I'll see if the script safely runs for the majority of people. Thx again. |
All times are GMT -5. The time now is 09:29 AM. |