checking the return code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking the return code
# 1  
Old 10-16-2008
Java checking the return code

hi
i have a file, i am reading line by line and checking a line contains a string ,

`grep "Change state" $LINE`
if [ "$?" -eq 0 ]
then
echo "The line contains---"
else
echo "The line does not contains---"


i need to check the return code , but i am getting an error

please help

thanks
Satya
# 2  
Old 10-16-2008
Don't use backticks, the redirection throws the output away:

Code:
grep "Change state" $LINE > /dev/null 2>&1
if [ "$?" -eq 0 ]
then
echo "The line contains---"
else
echo "The line does not contains---"

# 3  
Old 10-16-2008
hi Franklin,
even if the line contains that string also it is not going into the if block,

pleae its urgent
# 4  
Old 10-16-2008
Parameter of grep is filename not the line, you can give like

echo $LINE |grep -q "Change state"
if [ "$?" -eq 0 ]
then
echo "The line contains---"
else
echo "The line does not contains---"
# 5  
Old 10-16-2008
The variable $LINE could be empty, try to echo the variable before the grep command.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How could I use the value of return code

Hello, I am woring on a script where I am getting strange situation.This script actually fetch the source code and tar that code and send to NAS location.This code resides in MKS tool...and we are fetching the source code on checkpoint label basis and script is working fine.First it synch the... (0 Replies)
Discussion started by: anuragpgtgerman
0 Replies

2. Shell Programming and Scripting

code checking

i was just wondering how would you check , beside the lock method, if an instance of another code is already running and if it is then output a message to the user saying the program is already running and exit!! the code is in BOURNE SHELLL!!! thanks in advance!! (3 Replies)
Discussion started by: bshell_1214
3 Replies

3. UNIX for Dummies Questions & Answers

Checking return value of commands in pipe

Hi, I am wondering how I can check the return value of all commands in a pipe such as gzip -dc file.gz | sort -u > output.txt If I run this sequence in bash and check $?, I get the return status from sort. But I want to know if the initial gzip failed. Similarly for longer pipe chains,... (6 Replies)
Discussion started by: btherl
6 Replies

4. Shell Programming and Scripting

return code help

Hello folks, I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1. Thanks Bash (5 Replies)
Discussion started by: learnbash
5 Replies

5. Shell Programming and Scripting

Need help with return code 1...

Hi Guys,, I am having a unix script which is running the DB2 Insert command. For the insert command, there were no records to be updated. SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000 + + echo 1 STAGE_RC=1 + ] ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

6. Shell Programming and Scripting

checking for return status between multiple commands

i have to run set of commands command1 command2 command3 command4 Now Whenever any of these command fails i should quit while capturing error message. Is there a better way then checking for $? after each command. (1 Reply)
Discussion started by: vickylife
1 Replies

7. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

8. Shell Programming and Scripting

asking about return code

hi all my system is linux red hat i have a script that runs some object . the object return some code to the system i see the code by writing echo $? i want to ask in the script if $? equals 14 how shell is do that in the script thanks (3 Replies)
Discussion started by: naamas03
3 Replies

9. Shell Programming and Scripting

Checking Return Codes of Background Processes

I'm trying to do the following: 1) Run a bunch of jobs in the background 2) Determine if any one of them returns with a non-zero exit status Here's what I've come up with so far: ########################################## #!/bin/ksh while } -lt 1024 ] do SLEEP_TIME=`expr 1024 -... (2 Replies)
Discussion started by: bergerj3
2 Replies

10. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question