Suggestion to replace a part of script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Suggestion to replace a part of script
# 1  
Old 12-09-2009
Question Suggestion to replace a part of script

I have the part of script:

if [ -f $tmp_file ]; then
make_command="make -f $temp_file"
print $make_command;
err_file="${sym_objdir}error.log"
$make_command 2>$err_file; cat $err_file;
[[ -f $err_file ]] && [[ -s $err_file ]] && exit 1;
exit 0
fi

Question is very simple.
By means of the above piece of script I am returning exit code as 1 on error. But if you see I am generating a file(err_file="${sym_objdir}error.log") to do so.
My requirement is to the keep the functionality same but avoid the use of $err_file.

Can some give me clue or way to do so?
# 2  
Old 12-09-2009
I think this should suffice:
Code:
if [ -f $temp_file ]; then
  make_command="make -f $temp_file"
  print $make_command;
  $make_command 
  exit $?
fi

IMO the blue exit statement can be left out if these are the last statements of your script.
# 3  
Old 12-09-2009
Code:
#fd 6 has the same target as STDOUT
exec 6>&1
#STDERR is redirected to fd 1 (which means any errors go straight through to the pipe and trigger exit 1).  if there are no errors, STDOUT is redirected to fd 6, which is now STDOUT
$make_command 2>&1 >&6 | exit 1

this way all you should need is

Code:
exec 6>&1
if [ -f $tmp_file ]; then
make_command="make -f $temp_file"
print $make_command;
$make_command 2>&1 >&6 | exit 1
#give fd 1 target of STDOUT again, then close fd 6
exec 1>&6 6>&-
exit 0
fi

see if it works for you.

---------- Post updated at 02:31 PM ---------- Previous update was at 02:28 PM ----------

Quote:
Originally Posted by Scrutinizer
I think this should suffice:
Code:
if [ -f $temp_file ]; then
  make_command="make -f $temp_file"
  print $make_command;
  $make_command 
  exit $?
fi

IMO the blue exit statement can be left out if these are the last statements of your script.
Smilie much simpler way than mine, and here i though i was all clever Smilie
# 4  
Old 12-09-2009
Java

@Scrutinizer
This option I guess will not work with me. Because make is returning some times exit code as 0(success) on errors too. I am not sure about how nor I can change make. So In my piece of code I am making sure that after meeting any kind of error while running make_command. I should be retuning exit code as 1.

The solution provided by you has assumption that make is retuning 1 on error and 0 on success but its not like that as mentioned above.
# 5  
Old 12-09-2009
I see, something like this then?
Code:
if [ -f $temp_file ]; then
  make_command="make -f $temp_file"
  print $make_command
  err=$($make_command 2>&1 1>/dev/tty)
  if [ -n "$err" ]; then
    printf "$err\n"
    exit 1
  fi
fi

# 6  
Old 12-10-2009
Quote:
Originally Posted by Ajay_84
@Scrutinizer
This option I guess will not work with me. Because make is returning some times exit code as 0(success) on errors too. I am not sure about how nor I can change make. So In my piece of code I am making sure that after meeting any kind of error while running make_command. I should be retuning exit code as 1.

The solution provided by you has assumption that make is retuning 1 on error and 0 on success but its not like that as mentioned above.
so you want to exit if there are any errors?

see if what i wrote works, it will directly pipe STDERR to exit 1, so any errors that pop up should trigger it immediately
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace part of string?

Hi Gurus, I need to replace part of string in file, the string format is below: I can use ABCD to find string, then replace values after "=" sign ABCD_XXX=value ABCD_YYY=value after replace ABCD_XXX=new_value ABCD_YYY=new_value my OS is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ... (9 Replies)
Discussion started by: green_k
9 Replies

2. UNIX for Beginners Questions & Answers

Script suggestion

I have a file which looks like ant1 1,2,3,4 bat1 ant1 5,6,7,8 bat2 I would like to have an O/p as ant1 1 bat1 ant1 2 bat1 ant1 3 bat1 ant1 4 bat1 ant1 5 bat2 ant1 6 bat2 ant1 7 bat2 ant1 8 bat2 Is it possible. Thanks for any suggestion (9 Replies)
Discussion started by: Indra2011
9 Replies

3. Shell Programming and Scripting

I need Help suggestion for script...

Using the korn shell in ubuntu or fedora, I need to compare two forms, each from different files and do the following, form-1 is the dominant form and must be compared to form-2, if the value in field1 of form-1 matches exactly the pre-filled in value in field1 of form2 then I display 'already... (2 Replies)
Discussion started by: smth333
2 Replies

4. Shell Programming and Scripting

Script Suggestion

I am trying to get output for fcs0 fcs1 side by side with "Date" "FCAdapter_Name" "Last Reset" "DMA_Res" "Adapter_Count" "Command_Res" for all the captured output in fcstat.out Am I missing any thing below, as its just showing same values all the coloums: #!/usr/bin/ksh head -30 fcstat.out... (2 Replies)
Discussion started by: aix_admin_007
2 Replies

5. Shell Programming and Scripting

Suggestion with script to cleanup

I need help with sed and awk scripts to search for Symmetrix ID=000090009902 and then grep its child disk devices associated to the dead paths and display them only, so that those dead devices can be removed. test01:/#powermt display dev=all Pseudo name=hdiskpower0 Symmetrix ID=000090009902... (0 Replies)
Discussion started by: aix_admin_007
0 Replies

6. Shell Programming and Scripting

Replace part of folder(s)

I have a script that will output folders that all end with "x.deb". I want a shell script snippet that removes the "x.deb" from all those folders. Thanks in advance. (27 Replies)
Discussion started by: pasc
27 Replies

7. Shell Programming and Scripting

Shell script - Replace just part of a single line in a file.....

Hey guy's.... I new here, But im working on a school project, and I am not really good at programming. In fact, this is the only programming class that I need because programming is not what I am majoring in. But I have everything done in this shell script except for this last part..... ... (9 Replies)
Discussion started by: hxdrummerxc
9 Replies

8. Shell Programming and Scripting

Replace line and field using SED and/or AWK or some other suggestion

QUESTION 1: How do you replace a specific line (i.e. line 4) with a new user defined line (i.e. the contents of SAMS’s name, history, math and English grades have been set already). I have been attempting to use SED (FYI: I don’t have GNU SED) or AWK, but haven’t had any luck. FYI: I am using... (1 Reply)
Discussion started by: thibodc
1 Replies

9. Shell Programming and Scripting

Replace a part of the string

Hi I need to Replace a part of string in between one complete string. For e.g.. in the file the value is as: jobnm_$code_xyz_001 In script we are having a variable code=$3, where $3=ab final output should be jobnm_ab_xyz_001. But it is not working. Your help will be... (1 Reply)
Discussion started by: vee_789
1 Replies

10. Shell Programming and Scripting

suggestion on shell script on copy with xargs

Hi, i am trying to copy files except the latest, my script goes here #! /bin/bash # to copy control files to a local DR server # copy latest files of archive #modified on 26-03-2009 # --get today date dt=` date +"%Y_%m_%d"` --get yesterdays date adt=`(date --date='1 day ago'... (1 Reply)
Discussion started by: saha
1 Replies
Login or Register to Ask a Question