Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › shell scripting help ( and / or logicals )
New Posts  All Forums:Forum Nav:

shell scripting help ( and / or logicals )

post #1 of 4
Thread Starter 
How would the following be coded in a Bash script:
Code:
if ( ($variable1 == "true" ) || ($variable1 == "false" && $variable2 == "true") )

I can generally hold me own when it comes to shell scripting, but I'm stumped on this one problem; despite it being rather basic.
post #2 of 4
Thread Starter 
erm, after typing that out, I realised it's a dumb question as it can be normalised. thus resulting in the following code:
Code:
if [[ $variable1 == true ]] || [[ $variable2 == true ]; then
I really need to go bad to bed sleepysmiley03.gif


However anyone does fancy answering the original question, purely for academic purposes, then I'd welcome the education smile.gif
post #3 of 4
Quote:
Originally Posted by Plan9 View Post

erm, after typing that out, I realised it's a dumb question as it can be normalised. thus resulting in the following code:
Code:
if [[ $variable1 == true ]] || [[ $variable2 == true ]; then
I really need to go bad to bed sleepysmiley03.gif


However anyone does fancy answering the original question, purely for academic purposes, then I'd welcome the education smile.gif

I think I got the original question answered with the following code. I haven't done much testing but it seems to work like it should so far:
Code:
#!/bin/bash

var1=true
var2=false

if [[ $var1 == true ]] || ([[ $var1 == false ]] && [[ $var2 == true ]]); then
        echo "success"
else
        echo "fail"
fi

Play with the values of var1 and var2 to test for yourself
Edited by Nixalot - 3/11/13 at 7:37pm
post #4 of 4
Thread Starter 
Quote:
Originally Posted by Nixalot View Post

I think I got the original question answered with the following code. I haven't done much testing but it seems to work like it should so far:
Code:
#!/bin/bash

var1=true
var2=false

if [[ $var1 == true ]] || ([[ $var1 == false ]] && [[ $var2 == true ]]); then
        echo "success"
else
        echo "fail"
fi

Play with the values of var1 and var2 to test for yourself

You know, I thought I tried that but obvious I screwed something up massively because my code didn't work and that did.

Thanks mate. +reps
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › shell scripting help ( and / or logicals )