•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,519 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,806 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 2009 | Replies: 2
![]() |
•
•
Join Date: Aug 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi All,
Small can some please let me know hpw to use logical OR in csh scripts, below is the code line which is not running and i don't know why it is entring in "if" statement, even though i'm inputing value "1",
set ans = $<
echo $ans
if ( $ans != 1 || $ans != "2" ) then
echo "Invalid option selected. Exixting from the from the script $0 ."
exit 0
endif
It goes in if clause and then exits from the script
Any suggestions pls .???
Small can some please let me know hpw to use logical OR in csh scripts, below is the code line which is not running and i don't know why it is entring in "if" statement, even though i'm inputing value "1",
set ans = $<
echo $ans
if ( $ans != 1 || $ans != "2" ) then
echo "Invalid option selected. Exixting from the from the script $0 ."
exit 0
endif
It goes in if clause and then exits from the script
Any suggestions pls .???
Because 1 != 2. If you want it to enter the if statement only when the input is not 1 and not 2, then you need to use the logical and (&&), not the logical (or).
If you wanted to enter the loop only if the answer is either 1 or 2, then you would use the logical or. i.e.
but, when you invert the == to !=, then you must also invert the or to an and, because every number is either not equal to one or not equal to two, one and two included.
If you wanted to enter the loop only if the answer is either 1 or 2, then you would use the logical or. i.e.
if ( $ans == 1 || $ans == 2 ) then
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Aug 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Because 1 != 2. If you want it to enter the if statement only when the input is not 1 and not 2, then you need to use the logical and (&&), not the logical (or).
If you wanted to enter the loop only if the answer is either 1 or 2, then you would use the logical or. i.e.
but, when you invert the == to !=, then you must also invert the or to an and, because every number is either not equal to one or not equal to two, one and two included.if ( $ans == 1 || $ans == 2 ) then
Thanks mate Its working now !!!
It's an logical error from part ..
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Logical operations and data-checks (Java)
- Python Logical "OR": (Python)
- Regular Expressions (C#)
- Logical Operator help (Java)
- Need help writing a program (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: Help with sed command please.
- Next Thread: Reading a mail using shell script



Linear Mode