![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cannot get the logic | dineshr85 | Shell Programming and Scripting | 3 | 10-11-2007 07:34 AM |
| expand logic for > and < | pbsrinivas | Shell Programming and Scripting | 0 | 08-10-2007 09:59 AM |
| Strange Logic | ganesh123 | Shell Programming and Scripting | 5 | 03-20-2007 05:08 PM |
| Need help in genrating the logic | amitjha | Shell Programming and Scripting | 6 | 11-08-2006 06:45 AM |
| what the logic | ramneek | IP Networking | 2 | 09-05-2005 07:42 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
If Then Else Logic
I am obviously new to Unix Script writing, and I think I am trying to do this in SQL when im not in a SQL environment. What I need to do is the following
Code:
EXTRACT_ROW_COUNT=`grep Number $REFERENCE_LOG"extract_concern.log" | sed '/Number of rows exported:/s/.*:[^0-9]*\([0-9][0-9]*\)$/\1/'` LOADED_ROW_COUNT=`db2 -x "select count(*) from CENREF.REF_CONCERN_LU_TBL_B"` IF $EXTRACT_ROW_COUNT <> 0 and $EXTRACT_ROW_COUNT = $LOADED_ROW_COUNT THEN nohup $REFERENCE_SCRIPT"renme_ref_concern.sh" & ELSE echo "LOAD INCOMPLETE" > $REFERENCE_LOG"CONCERN_LOAD_FAILURE.LOG" end IF I have been studing the IF man pages but they dont seem to do what I need. Im probably overlooking something, can you point me in the right direction? |
|
||||
|
Your problem is you are looking in the wrong place. ;-)
The shell construct "if [ ...] ; then" is utilizing a command external to the shell: /usr/bin/test. In fact "[....]" is just an alternative way to write "test ...." and branch on the errorlevel (return value) of this command. You have the following (basic) options in test, more to be found on the manpage of test: (for the following we assume x=5 and y=10) -gt "greater then" compare (integer) values: test $x -gt $y => returns FALSE -ge "greater or equal" -lt "lower then" -le "lower equal" -eq "equal" -ne "not equal" -a logical AND. Example: test "$x -gt 0 -a $y -ge x" => returns TRUE -o logical OR. Analogous to above \(...\) grouping. Example: test "\( $x -gt 0 \) -a \( $y -gt $x -o $y -gt 0 \)" -n non-zero TRUE if a string is not empty -z zero TRUE if a string is empty ("") I hope this helps. bakunin |
|
||||
|
Quote:
This looks a bit more streight forward to me...but again do you have a detailed link that can clear up some questions for me. For example Code:
test $x -gt $y => returns FALSE |
|
||||
|
Quote:
Quote:
Code:
x=5 y=10 test $x -gt $y ; echo $? test $y -gt $x ; echo $? bakunin |
|
||||
|
Quote:
To answer your question: Code:
$ $ uname -a SunOS scrbtpcdkbry211 5.10 Generic_118833-36 sun4u sparc SUNW,Sun-Fire-V490 $ echo $SHELL /bin/ksh |
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|