12-24-2006
In bash the return code of a prog is in $?. Usually exit status 0 = success and 1 = failure.
If we look in the manpage for grep we find:
Normally, exit status is 0 if selected lines are found and 1 otherwise. But the exit status is 2 if an error occurred, unless the -q or --quiet or --silent option is used and a selected line is found.
Based on that, an example of usage:
---------------------------
#!/bin/bash
/bin/grep search_string file
if [ $? -eq 1 ];then
echo "String not found."
fi
---------------------------
Hope that gets you on your way.
Kent
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I face some problem with handling of nulls. I declare a variable - say i - and intialise to 0. Later I read it from console, wherein if I dont give any variable and press return key, I get this error:
"0403-004 Specify a parameter with this command"
Is there anyway to handle this error?
... (3 Replies)
Discussion started by: mohanprabu
3 Replies
2. UNIX for Advanced & Expert Users
Hi,
I am using few ISQL statements to update and delete from a few tables in sybase, now i want to roll back the transaction when any of the statements fail.How i can i capture these errors in the shell scripts.Please advise.
Thanks,
Gopi (4 Replies)
Discussion started by: bhgopi
4 Replies
3. Shell Programming and Scripting
Hi
Please let me know is there any way through which I can find out errors & do debugging in FTP scripts.
Thanks
Sourabh
TCS (1 Reply)
Discussion started by: sourabhshakya
1 Replies
4. Shell Programming and Scripting
Hi All,
Is interrupt handling possible in k shell?
Say if the user press CTRL-C or CTRl-D,I want to perform a particular action before terminating?
Thnaks! (2 Replies)
Discussion started by: prasperl
2 Replies
5. Shell Programming and Scripting
Hi all
I've got a question regarding error handling in shell scripts. My background is mainly object oriented programming languages, but for a year or so I've been doing more and more (bash) shell scripting (which I quite enjoy by the way).
To handle errors in my scripts I... (3 Replies)
Discussion started by: script_man
3 Replies
6. Shell Programming and Scripting
Hi,
Please help me with the below situation where I have to handle the parameters passed to a function in a unique way.
Below is the code, which I am trying to execute. I basically want to pass the parameter to a function, where I am trying to get user input into array(s). I want to name... (7 Replies)
Discussion started by: bharath.gct
7 Replies
7. Shell Programming and Scripting
Hi all...
Please help me with this questions.
I am not good at shell scripting.
1) It seems like there are many ways that we can run the shell scripts.
what is the difference between each one?
i)./shell_script.sh
ii).(space)./ shell_script.sh
iii)sh shell_script.sh
... (3 Replies)
Discussion started by: sanskumar2003
3 Replies
8. Shell Programming and Scripting
AIX 7.1
Here's the script
#!/bin/ksh
find . -print > filelist.txt
backup -ivqf/dev/rmt0 < filelist.txt > backup.log
if ; then
echo "Backup to tape failed!" >> backup.log
else
echo "Backup to tape successfull!" >> backup.log
fi
mail -v -s "Backup report" maillist < backup.log
... (4 Replies)
Discussion started by: landog
4 Replies
9. Shell Programming and Scripting
Hi ,
My Script work as below
1-
On server 1
execute script1.sh ,
through this script one parameter file is generated as file.txt this is to transfer on server 2
2-
After reaching on server2 other shell script script2.sh execute using parameter file file.txt
This generate file... (1 Reply)
Discussion started by: kaushik02018
1 Replies
10. Shell Programming and Scripting
Hello
I have a file which has around 120 lines of commands.
I am trying to write a shell script like which reads the 'command' file and executes line by line with some additional (common argument) with maximum 6 commands active at a time. Each of these commands when executed takes time... (5 Replies)
Discussion started by: JackyShane_36
5 Replies
LEARN ABOUT REDHAT
adsl-setup
ADSL-SETUP(8) System Manager's Manual ADSL-SETUP(8)
NAME
adsl-setup - Shell script to configure Roaring Penguin PPPoE client
SYNOPSIS
adsl-setup
DESCRIPTION
adsl-setup is a shell script which prompts you for various pieces of information and sets up an /etc/sysconfig/network-scripts/ifcfg-ppp0
configuration script for the adsl-start, adsl-stop and adsl-connect scripts.
AUTHOR
adsl-setup was written by David F. Skoll <dfs@roaringpenguin.com>.
The pppoe home page is http://www.roaringpenguin.com/pppoe/.
SEE ALSO
pppoe(8), adsl-start(8), adsl-stop(8), adsl-connect(8), pppd(8), pppoe.conf(5), adsl-status(8), pppoe-sniff(8), pppoe-relay(8), pppoe-
server(8)
4th Berkeley Distribution 21 February 2000 ADSL-SETUP(8)