boolean expression in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting boolean expression in bash
# 1  
Old 08-25-2011
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 `]'
Code:
if [ $# != 1 || [ "$1" != "ALL" && "$1" != "PART" ] ]; then
                # NOTIFY ERROR...
fi

And... I'd also appreciate a link to bash documents that explain these things. All what I've seen (a lot) is quite superficial.
# 2  
Old 08-25-2011
You can't nest [ ].

You can't use && inside [ ]. You can inside [[ ]].

Code:
 if [ $# != 1 ] || [[ "$1" != "ALL" && "$1" != "PART" ]]; then
                # NOTIFY ERROR...
fi

test constructs
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-25-2011
Thanks!!

Quote:
Originally Posted by Corona688
You can't nest [ ].

You can't use && inside [ ]. You can inside [[ ]].
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to assign result of boolean expression?

Hello I would to write the test on one line like : 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 -o ; then do_something fi Any help is welcome (2 Replies)
Discussion started by: jcdole
2 Replies

2. 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

3. 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

4. Shell Programming and Scripting

Hi im new to bash scripting I want to know what does the regex expression do ??

# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi (1 Reply)
Discussion started by: kevin298
1 Replies

5. UNIX for Dummies Questions & Answers

Im new to bash scriping and i found this expression on a bash script what does this mean.

# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi espeacailly the top regex part? ---------- Post updated at 06:58 PM ---------- Previous update was... (1 Reply)
Discussion started by: kevin298
1 Replies

6. 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

7. Shell Programming and Scripting

Need help in Regular expression in bash shell

hi, I have written a script to search MAC address in a given directory. MAC address would be in format XX.XX.XX.XX. The digits contain hexadecimal numbers. For this i have used grep as follows. grep -rn '^\{1,2\}\.\{1,2\}\.\{1,2\}\.\{1,2\}\$' * This is not working as required.... (17 Replies)
Discussion started by: flamingo_l
17 Replies

8. Shell Programming and Scripting

[Bash]Function returning a boolean

Hello all, I would like to know if it is possible to return a the result of a boolean expression from a function like this function() { # some code return || } and what will be the return value ? Thank you for help. (6 Replies)
Discussion started by: dolphin06
6 Replies

9. 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

10. Shell Programming and Scripting

how to use regular expression in Bash Shell Scripting

Hi, Actually i have written one test.sh (shell program) in bash. Here i have a variables $a which stored the value package1. Now I want to write a regular expression inside the if command that "if $a variable contains letter p in the begining of the value package1 then it is coming true.... (5 Replies)
Discussion started by: sunitachoudhury
5 Replies
Login or Register to Ask a Question