How to assign result of boolean expression?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to assign result of boolean expression?
# 1  
Old 07-19-2017
How to assign result of boolean expression?

Hello

I would to write the test on one line like :
Code:
declare -i x=0 y=0 

........
some code assign value 0 or 1 to x and y
........

# if either x or y or both is set to 1, then do something
if  [ $x -gt 0 ] -o [ $y -gt 0 ] ; then
   do_something
fi

Any help is welcome
# 2  
Old 07-19-2017
-o is OR within [ ] (and in test arguments)
|| is OR in the shell
So it is either
Code:
if  [ $x -gt 0 -o $y -gt 0 ] ; then

or
Code:
if  [ $x -gt 0 ] || [ $y -gt 0 ] ; then

These 2 Users Gave Thanks to MadeInGermany For This Post:
# 3  
Old 07-22-2017
Quote:
Originally Posted by MadeInGermany
-o is OR within [ ] (and in test arguments)
|| is OR in the shell
So it is either
Code:
if  [ $x -gt 0 -o $y -gt 0 ] ; then

or
Code:
if  [ $x -gt 0 ] || [ $y -gt 0 ] ; then

Thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using boolean expression Bash script

Hi, Im trying to write a Bash script that calculates the least common subnet for two address. Theoretical: I have to change IP from decimal to binary, then apply XNOR on the two IPs. I tried to write this: #!/bin/bash echo "Ebter the first ip" read ip1 echo "Enter the second ip" read... (7 Replies)
Discussion started by: Miron
7 Replies

2. Shell Programming and Scripting

Remove a character and assign result to a variable

I am reading lines from a file that contain a number sign (#) before a three or four digit number: #1043 #677 I can remove the '#' and get just the number. However, I then want to assign that number to a variable and use it as part of a path further on in my program: /mydir/10/1043 for... (5 Replies)
Discussion started by: KathyB148
5 Replies

3. Shell Programming and Scripting

Assign awk gsub result to a variable

Hello, I have searched but failed to find what exactly im looking for, I need to eliminate first "." in a output so i can use something like the following echo "./abc/20141127" | nawk '{gsub("^.","");print}' what i want is to use gsub result later on, how could i achieve it? Let say... (4 Replies)
Discussion started by: EAGL€
4 Replies

4. Shell Programming and Scripting

Boolean expression

hi, im learning python language. and my teacher gives me this question on class: Boolean expression : not (p or not q) what is the correct answer for that? i still dont understand, and please give me a link for a new beginner in python to learn. thanks (1 Reply)
Discussion started by: jazzyzha
1 Replies

5. UNIX for Dummies Questions & Answers

Assign SQL result in shell variable

Hi im trying to assign the result of the db2 command to a variable inside a shell script... : tab_cnt=`db2 "select count(*) from syscat.tables where tabname = 'ABC' and tabschema = 'MATT01'" |head -4|tail +4|cut -c 11` : echo $tab_cnt when i echo im getting a blank value.. im expecting... (1 Reply)
Discussion started by: matt01
1 Replies

6. Shell Programming and Scripting

boolean expression in bash

Can someone, please, help me to make this condition valid/accepted in bash? I really cannot. I'm stuck with the brackets... This one tells me: missing `]' if ]; then # NOTIFY ERROR... fi And... I'd also appreciate a link to bash documents that explain these things. All... (2 Replies)
Discussion started by: mamboknave
2 Replies

7. Shell Programming and Scripting

Boolean expression issues

Hi everybody: I'm working on a script to send emails with logs attached based on one single rule..."check if the number of errors has increased since the last time the script ran" Basically what my script does is read from a previous file with the last trace of errors the previous error... (3 Replies)
Discussion started by: hyunkel_01
3 Replies

8. Shell Programming and Scripting

Assign result to variable

Hi friends, firstly, i can run following expression and i took 100 value. sqlplus -s username/password@TTTEST @umt.sql umt.sql exists "select t.deger from parametre t where t.id=30". result of this query =100 i need to assign this value(100) to variable(for example x... (2 Replies)
Discussion started by: temhem
2 Replies

9. Shell Programming and Scripting

assign awk command result to a variable

#!/bin/sh # ## MYSTRING = `awk '/myApp.app/' /Users/$USER/Library/Preferences/loginwindow.plist` if then echo String not found defaults write /Users/$USER/Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -dict-add -string Hide -bool YES -string Path -string... (9 Replies)
Discussion started by: dedmakar
9 Replies

10. Shell Programming and Scripting

Regular expression boolean in perl

How can I find out, that whether a regular expression are matched or not(as a boolean)?! tnx in advance. (2 Replies)
Discussion started by: Zaxon
2 Replies
Login or Register to Ask a Question