Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-17-2013, 09:33 PM   #1
LQ Newbie
Registered: Nov 2012
Posts: 17

Rep: Reputation: Disabled
If statement with multiple parameters to meet

I have an existing csh script which I know works, but I need to update some links in it so that it will run on a different computer. After updating the links, the script won't work. I've narrowed it down to what the problem is and it's not related to the updates I just done and can't work out why it won't work. The issue is with the following if statement:

set a = (an integer)
set b = (an integer)

foreach entry
set c = (formula that produces an integer)
set d = (formula that produces an integer)

if ($c <= $a) then
if ($b <= $d) then
(run a set of commands)

Basically I want it to do is if both integers (c and d) are less than a and b, then do the commands, otherwise do nothing.

Any advice?
Old 01-18-2013, 03:45 PM   #2
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
You can use the "||" or operator or the "&&" and operator.
Old 01-18-2013, 04:42 PM   #3
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165
Another way ... and a more generalized way ... to approach a problem like this one is to split the problem into two consecutive halves.

First, you decide whichever one of however-many mutually exclusive "states" you are now in ... Then, you carry out the appropriate response for each "state."

For example, consider logic such as the following:

state = 0;
if (a > b) state = state + 1;
if (d > e) state = state + 2;
if (f > g) state = state + 4;

(Now, state has a unique value from 0 to 4+2+1=7, representing every possible combination of the above decisions. So...)

switch (state) {
case 0: ...
case 1: ...

In this way, you have explicitly separated the first concern, of "deciding what to do" (and of "how to make that decision"), from the second concern of "now, go and do the appropriate thing." In this way, you have now paved the way to expressing fairly-arbitrary decision logic in a way that will always be clear.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to comment multiple statement? johnabraham Linux - Newbie 4 12-20-2012 07:27 AM
[SOLVED] Bash Multiple If statement michijo Programming 7 02-21-2012 07:22 AM
multiple expression if statement s_linux SUSE / openSUSE 4 02-11-2012 08:02 AM
[SOLVED] if statement with multiple tasks ted_chou12 Linux - Newbie 3 02-02-2011 06:59 PM
How to do multiple comaprison in a IF statement pdklinux79 Linux - Newbie 4 06-11-2008 10:34 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:44 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration