Sponsored Content
Top Forums Shell Programming and Scripting How to use logical operators in multiple if statement Post 302528338 by IND123 on Tuesday 7th of June 2011 03:31:15 AM
Old 06-07-2011
The logical AND and OR conditions will remain same. Use "elif" in place of "Else if" and after the final else with the associated statement end the if block with "fi" .

Eg:


Code:
if [ $int1 = $int2 ]
then
       echo "int1 is equal to int2"
elif [ $int1 > $int2 ]
then
       echo "int1 is greater than int2"
else
     echo "int1 is smaller than int2"
fi

Alternative Way:

is equal to: eq
is not equal to: ne
is greater than: gt
is less than: lt
is greater than or equal to: ge
is less than or equal to: le

-a is same as using &&
-o is same as using ||

Note: Padding of space is mandatory before using '[' and ']'

Thank you.

Last edited by Franklin52; 06-07-2011 at 06:21 AM.. Reason: Please use code tags, thank you
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

multiple Logical statement

hi I have following if condition line_by_line="0000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt" if then echo "Exclusion criteria" else echo "Not exclusion criteria" fi above condition works perfectley but if i add one more logical condition... (3 Replies)
Discussion started by: mahabunta
3 Replies

2. Shell Programming and Scripting

Logical AND within a case statement ??

Hi there, probably a really simple question to answer but i cant seem to find it can I use a logical AND (&&) within a CASE statement ie (ps this is useless syntax but youll get the idea case "$var1","$var2" in 'Billy' && 'Bobby') ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

3. Shell Programming and Scripting

Multiple Logical Operator Issues ...

Hi folks I have a snippet of code Which is like this If ( ( A || B || C ) && D ) then Do some thing.... elif exit fi How to rephrase this and use it so I dont get any Errors ... Looking out for helpful replies .. Thanks & Regards Srikanth GR (1 Reply)
Discussion started by: srikanthgr1
1 Replies

4. Shell Programming and Scripting

And and OR Operators with If Statement.

Hi All, I have 2 variables. Result1 and Result2. I want to put a condition that if Both are True then echo "All True" Else Show Error. Right now i am doing this and getting error. if ; then echo "All True" else echo "Failed" fi; Error. line 8: ' Solution: Looking for (2 Replies)
Discussion started by: mkashif
2 Replies

5. Shell Programming and Scripting

Can you use logical operators in a case statement (bash)?

I'm pretty sure I already know the answer to this, but I want to make sure I'm not overlooking anything. I'm working on a log monitoring script and every 10 lines I want to display a summary of events. The thing is, there are a lot of possible events, that likely won't have happened, so I only want... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

6. UNIX for Dummies Questions & Answers

issue with multiple logical operators

Hi, shell is /bin/ksh I am trying to do the following in my code.. but its showing me an error if ] && ] ]]; then echo "id is $ida and chk_dy is $chk_dy" fi the error I get is syntax error at line 23 : `"$ida"' unexpected I need to execute the... (2 Replies)
Discussion started by: nss280
2 Replies

7. Shell Programming and Scripting

ksh Multiple Pattern Matching Operators

I figured this would be simple, but I am stuck. Variable longpath="/dir1/dir2/dir3/filename.stuff.morestuff.garbage" I want to end up with just "filename.extra.moreextra". So, I want to get rid of the path and .garbage I want to do this with just ksh internals. So, no sed,grep,awk,expr,... (4 Replies)
Discussion started by: Topaz
4 Replies

8. Shell Programming and Scripting

Using Logical Expression in an AWK statement

I'm would to create a script that would give me the results below. Please note the spaces in the log file are actually commas(",".) Log file Data 0:00 21:15 899 43 31 12 25.39 0:00 21:20 736 34 19 15 35.39 0:00 21:20 776 41 28 13 ... (3 Replies)
Discussion started by: ravzter
3 Replies

9. Shell Programming and Scripting

Implementing operators on multiple fields

Hallo Friends, Have a look at my script: awk -F',' '$14==9100' *_201304*.csv|wc -l > pax1; awk -F',' '$14==9101' *_201304*.csv|wc -l >>pax1; awk -F',' '$14==9102' *_201304*.csv|wc -l >>pax1; awk -F',' '$14==9103' *_201304*.csv|wc -l >>pax1 I would like to include field 42. like below ... (9 Replies)
Discussion started by: kekanap
9 Replies

10. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies
DateTime::Event::Recurrence(3pm)			User Contributed Perl Documentation			  DateTime::Event::Recurrence(3pm)

NAME
DateTime::Event::Recurrence - DateTime::Set extension for create basic recurrence sets SYNOPSIS
use DateTime; use DateTime::Event::Recurrence; my $dt = DateTime->new( year => 2000, month => 6, day => 20, ); my $daily_set = DateTime::Event::Recurrence->daily; my $dt_next = $daily_set->next( $dt ); my $dt_previous = $daily_set->previous( $dt ); my $bool = $daily_set->contains( $dt ); my @days = $daily_set->as_list( start => $dt1, end => $dt2 ); my $iter = $daily_set->iterator; while ( my $dt = $iter->next ) { print ' ', $dt->datetime; } DESCRIPTION
This module provides convenience methods that let you easily create "DateTime::Set" objects for various recurrences, such as "once a month" or "every day". You can also create more complicated recurrences, such as "every Monday, Wednesday and Thursday at 10:00 AM and 2:00 PM". USAGE
o yearly monthly weekly daily hourly minutely secondly These methods all return a new "DateTime::Set" object representing the given recurrence. my $daily_set = DateTime::Event::Recurrence->daily; If no parameters are given, then the set members each occur at the beginning of the specified recurrence. For example, by default, the "monthly()" method returns a set containing the first day of each month. Without parameters, the "weekly()" method returns a set containing Mondays. However, you can pass in parameters to alter where these datetimes fall. The parameters are the same as those given to the "DateTime::Duration" constructor for specifying the length of a duration. For example, to create a set representing a daily recurrence at 10:30 each day, we write this: my $daily_at_10_30_set = DateTime::Event::Recurrence->daily( hours => 10, minutes => 30 ); To represent every Tuesday (second day of the week): my $weekly_on_tuesday_set = DateTime::Event::Recurrence->weekly( days => 2 ); A negative duration counts backwards from the end of the period. This is done in the same manner as is specified in RFC 2445 (iCal). Negative durations are useful for creating recurrences such as the last day of each month: my $last_day_of_month_set = DateTime::Event::Recurrence->monthly( days => -1 ); You can also provide multiple sets of duration arguments, such as this: my $set = DateTime::Event::Recurrence->daily ( hours => [ 10, 14, -1 ], minutes => [ 15, 30, -15 ], ); This specifies a recurrence occurring every day at these 9 different times: 10:15, 10:30, 10:45, # +10h ( +15min / +30min / last 15min (-15) ) 14:15, 14:30, 14:45, # +14h ( +15min / +30min / last 15min (-15) ) 23:15, 23:30, 23:45, # last 1h (-1) ( +15min / +30min / last 15min (-15) ) To create a set of recurrences occurring every thirty seconds, we could do this: my $every_30_seconds_set = DateTime::Event::Recurrence->minutely( seconds => [ 0, 30 ] ); The following is also valid. See the section on the "interval" parameter: my $every_30_seconds_set = DateTime::Event::Recurrence->secondly( interval => 30 ); Invalid DateTimes Invalid values are skipped at run time. For example, when days are added to a month, the result is checked for a nonexisting day (such as 31 or 30), and the invalid datetimes are skipped. Another example of this would be creating a set via the "daily()" method and specifying "hours => 25". The "days" Parameter The "days" parameter can be combined with yearly, monthly, and weekly recurrences, resulting in six possible meanings: # tuesday of every week my $set = DateTime::Event::Recurrence->weekly( days => 2 ); # 10th day of every month my $set = DateTime::Event::Recurrence->monthly( days => 10 ); # second tuesday of every month my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days => 2 ); # 10th day of every year my $set = DateTime::Event::Recurrence->yearly( days => 10 ); # 10th day of every december my $set = DateTime::Event::Recurrence->yearly( months => 12, days => 10 ); # second tuesday of every year my $set = DateTime::Event::Recurrence->yearly( weeks => 2, days => 2 ); Week days can also be called by name, as is specified in RFC 2445 (iCal): my $weekly_on_tuesday_set = DateTime::Event::Recurrence->weekly( days => 'tu' ); The "days" parameter defaults to "the first day". See also the section on the "week start day" parameter. # second monday of every month my $set = DateTime::Event::Recurrence->monthly( weeks => 2 ); The "interval" and "start" Parameters The "interval" parameter represents how often the recurrence rule repeats. The optional "start" parameter specifies where to start counting: my $dt_start = DateTime->new( year => 2003, month => 6, day => 15 ); my $set = DateTime::Event::Recurrence->daily ( interval => 11, hours => 10, minutes => 30, start => $dt_start, ); This specifies a recurrence that happens at 10:30 on the day specified by "start => $dt", and then every 11 days before and after $dt. So we get a set like this: ... 2003-06-04T10:30:00, 2003-06-15T10:30:00, 2003-06-26T10:30:00, ... In this case, the method is used to specify the unit, so "daily()" means that our unit is a day, and "interval => 11" specifies the quantity of our unit. The "start" parameter should have no time zone. The "week_start_day" Parameter The "week_start_day" parameter is intended for internal use by the "DateTime::Event::ICal" module, for generating RFC2445 recurrences. The "week_start_day" represents how the 'first week' of a period is calculated: "mo" - this is the default. The first week is one that starts in monday, and has the most days in this period. "tu", "we", "th", "fr", "sa", "su" - The first week is one that starts in this week-day, and has the most days in this period. Works for "weekly" and "yearly" recurrences. "1tu", "1we", "1th", "1fr", "1sa", "1su" - The first week is one that starts in this week-day, and has all days in this period. This works for "weekly()", "monthly()" and "yearly()" recurrences. Time Zones Recurrences are created in the 'floating' time zone, as specified in the "DateTime" module. If you want to specify a time zone for a recurrence, you can do this by calling "set_time_zone()" on the returned set: my $daily = DateTime::Event::Recurrence->daily; $daily->set_time_zone( 'Europe/Berlin' ); You can also pass a "DateTime.pm" object with a time zone to the set's "next()" and "previous()" methods: my $dt = DateTime->today( time_zone => 'Europe/Berlin' ); my $next = $daily->next($dt); A recurrence can be affected DST changes, so it would be possible to specify a recurrence that creates nonexistent datetimes. Because "DateTime.pm" throws an exception if asked to create a non-existent datetime, please be careful when setting a time zone for your recurrence. It might be preferable to always use "UTC" for your sets, and then convert the returned object to the desired time zone. Leap Seconds There are no leap seconds, because the recurrences are created in the 'floating' time zone. The value 60 for seconds (the leap second) is ignored. If you really want the leap second, then specify the second as "-1". AUTHOR
Flavio Soibelmann Glock fglock@pucrs.br CREDITS
The API was developed with help from the people in the datetime@perl.org list. Special thanks to Dave Rolsky, Ron Hill and Matt Sisk for being around with ideas. If you can understand what this module does by reading the docs, you should thank Dave Rolsky. If you can't understand it, yell at him. He also helped removing weird idioms from the code. Jerrad Pierce came with the idea to move "interval" from DateTime::Event::ICal to here. COPYRIGHT
Copyright (c) 2003 Flavio Soibelmann Glock. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. SEE ALSO
datetime@perl.org mailing list DateTime Web page at http://datetime.perl.org/ DateTime - date and time :) DateTime::Set - for recurrence-set accessors docs. You can use DateTime::Set to specify recurrences using callback subroutines. DateTime::Event::ICal - if you need more complex recurrences. DateTime::SpanSet - sets of intervals, including recurring sets of intervals. perl v5.10.0 2005-05-12 DateTime::Event::Recurrence(3pm)
All times are GMT -4. The time now is 10:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy