if statament

This is a discussion on if statament within the Linux Programming forums, part of the Platform Specific Boards category; hello! In my script I have to check a condition using if statement but I'm not sure about the syntax ...

  1. #1
    quo
    quo is offline
    Registered User
    Join Date
    May 2011
    Posts
    116

    if statament

    hello!

    In my script I have to check a condition using if statement
    but I'm not sure about the syntax
    Here's what I do:

    Code:
    if [[ "$var1" == aa ]]
    but I want to include also:

    Code:
    if [[ "$var1" == aa ]] -o [[ "$var1" == bb ]]
    in order to check if var1 is equal to aa OR to bb
    but it doesn't work

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    $ a=2
    $ if [[ $a == 2 || $a == 3 ]]; then echo yes; fi
    yes
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    quo
    quo is offline
    Registered User
    Join Date
    May 2011
    Posts
    116
    Quote Originally Posted by Salem View Post
    $ a=2
    $ if [[ $a == 2 || $a == 3 ]]; then echo yes; fi
    yes
    thanks!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21