×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles
    Revision as of 13:59, 7 April 2006 by imported>mutante

    The great GNU Bourne-Again Shell

    Bash is the shell, or command language interpreter, that will appear in the GNU Operating System.

    Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh).

    Bash Links

    Useful Keyboard combinations in Bash

    • ^a = start of line


    Operators

    Assignment Operators

    =
    

    All-purpose assignment operator, which works for both arithmetic and string assignments.Do not confuse the "=" assignment operator with the = test operator.

    Arithmetic Operators =

    +
    

    plus

    -
    

    minus

    *
    

    multiplication

    /
    

    division

    **
    

    exponentiation

    %
    

    modulo, or mod (returns the remainder of an integer division operation)

    +=
       "plus-equal" (increment variable by a constant). let "var += 5" results in var being incremented by 5.
    
    -=
    

    "minus-equal" (decrement variable by a constant)

    *=
    

    "times-equal" (multiply variable by a constant). let "var *= 4" results in var being multiplied by 4.

    /=
    "slash-equal" (divide variable by a constant)
    
    %=
    "mod-equal" (remainder of dividing variable by a constant)
    

    Logical Operators

    &&
    

    and (logical)

    ||
    

    or (logical)

    Comparison Operators

    Integers
    -eq
    

    is equal to. if [ "$a" -eq "$b" ]

    -ne
    

    is not equal to. if [ "$a" -ne "$b" ]

    -gt
    

    is greater than. if [ "$a" -gt "$b" ]

    -ge
    

    is greater than or equal to if. [ "$a" -ge "$b" ]

    -lt
    

    is less than. if [ "$a" -lt "$b" ]

    -le
    

    is less than or equal to. if [ "$a" -le "$b" ]

    <
    

    is less than. (within double parentheses) (("$a" < "$b"))

    <=
    

    is less than or equal to. (within double parentheses). (("$a" <= "$b"))

    >
    

    is greater than (within double parentheses). (("$a" > "$b"))

    >=
    

    is greater than or equal to (within double parentheses). (("$a" >= "$b"))


    Strings
    =
    

    is equal to. if [ "$a" = "$b" ]

    ==
    

    is equal to. if [ "$a" == "$b" ]

    !=
    

    is not equal to. if [ "$a" != "$b" ]

    <
    

    is less than, in ASCII alphabetical order

    >
    

    is greater than, in ASCII alphabetical order

    -z
    

    string is "null", that is, has zero length

    -n
    

    string is not "null".

    Bitwise Operators

    <<
    

    bitwise left shift (multiplies by 2 for each shift position)

    <<=
    

    "left-shift-equal" let "var <<= 2" results in var left-shifted 2 bits (multiplied by 4)

    >>
    

    bitwise right shift (divides by 2 for each shift position)

    >>=
    

    "right-shift-equal" (inverse of <<=)

    &
    

    bitwise and

    &=
    

    bitwise and-equal

    |
    

    bitwise OR

    |=
    

    bitwise OR-equal

    ~
    

    bitwise negate

    !
    

    bitwise NOT

    ^
    

    bitwise XOR

    ^=
    

    bitwise XOR-equal


    Misc Operators

    ,
    

    comma operator . The comma operator chains together two or more arithmetic operations. All the operations are evaluated (with possible side effects), but only the last operation is returned.

    also see: Bash Scripts

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.