×
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

    The great GNU Bourne-Again Shell[edit]

    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[edit]

    Useful Keyboard combinations in Bash[edit]

    With control (crtl)[edit]

    • crtl-a = start of line
    • crtl-e = end of line
    • crtl-l = clears the screen, like command clear
    • crtl-p = previous command from history, like page up key
    • crtl-r = reverse search in history(incremental)

    With escape(esc)[edit]

    • esc-f = one word forward
    • esc-b = one word backward

    Operators[edit]

    Assignment Operators[edit]

    =
    

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

    Arithmetic Operators[edit]

    +
    

    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[edit]

    &&
    

    and (logical). if [ $condition1 ] && [ $condition2 ]

    ||
    

    or (logical). if [ $condition1 ] || [ $condition2 ]

    Dont confuse those with #Conditional executing.

    Comparison Operators[edit]

    Integers[edit]
    -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[edit]
    =
    

    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[edit]

    <<
    

    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[edit]

    ,
    

    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.

    Conditional executing[edit]

    command1 && command2
    

    command2 is executed if, and only if, command1 returns an exit status of zero. (exit status zero means succesful)

    command1 || command2
    

    command2 is executed if and only if command1 returns a non-zero exit status. (non-zero exit status means failed)

    command1 && command2 || command3 
    

    if command1 is executed successfully then shell will run command2 and if command1 is not successful then command3 is executed.

    Wildcards / regex[edit]

    These can be used on filenames.

    *
    

    zero or more characters

    ?
    

    exactly one character

    [abcde]
    

    exactly one character listed

    [a-e]
    

    exactly one character in the given range

    [!abcde]
    

    any character that is not listed

    [!a-e]
    

    any character that is not in the given range

    {debian,linux}
    

    exactly one entire word in the options given

    You can use wildcards with any command that accepts file names as arguments.

    also see: Bash Scripts

    <man>bash</man>

    Bash built-in commands[edit]

    GNU bash, version 2.05a.0(1)-release (i386-pc-linux-gnu)
    These shell commands are defined internally.  Type `help' to see this list.
    Type 'help name' to find out more about the function `name'.
    Use 'info bash' to find out more about the shell in general.
    
    A star (*) next to a name means that the command is disabled.
    
     %[DIGITS | WORD] [&]               . filename
     :                                  [ arg... ]
     alias [-p] [name[=value] ... ]     bg [job_spec]
     bind [-lpvsPVS] [-m keymap] [-f fi break [n]
     builtin [shell-builtin [arg ...]]  case WORD in [PATTERN [| PATTERN].
     cd [-PL] [dir]                     command [-pVv] command [arg ...]
     compgen [-abcdefgjkvu] [-o option] complete [-abcdefgjkvu] [-pr] [-o 
     continue [n]                       declare [-afFrxi] [-p] name[=value
     dirs [-clpv] [+N] [-N]             disown [-h] [-ar] [jobspec ...]
     echo [-neE] [arg ...]              enable [-pnds] [-a] [-f filename] 
     eval [arg ...]                     exec [-cl] [-a name] file [redirec
     exit [n]                           export [-nf] [name ...] or export 
     false                              fc [-e ename] [-nlr] [first] [last
     fg [job_spec]                      for NAME [in WORDS ... ;] do COMMA
     function NAME { COMMANDS ; } or NA getopts optstring name [arg]
     hash [-r] [-p pathname] [-t] [name help [-s] [pattern ...]
     history [-c] [-d offset] [n] or hi if COMMANDS; then COMMANDS; [ elif
     jobs [-lnprs] [jobspec ...] or job kill [-s sigspec | -n signum | -si
     let arg [arg ...]                  local name[=value] ...
     logout                             popd [+N | -N] [-n]
     printf format [arguments]          pushd [dir | +N | -N] [-n]
     pwd [-PL]                          read [-ers] [-t timeout] [-p promp
     readonly [-anf] [name ...] or read return [n]
     select NAME [in WORDS ... ;] do CO set [--abefhkmnptuvxBCHP] [-o opti
     shift [n]                          shopt [-pqsu] [-o long-option] opt
     source filename                    suspend [-f]
     test [expr]                        time [-p] PIPELINE
     times                              trap [arg] [signal_spec ...] or tr
     true                               type [-apt] name [name ...]
     typeset [-afFrxi] [-p] name[=value ulimit [-SHacdflmnpstuv] [limit]
     umask [-p] [-S] [mode]             unalias [-a] [name ...]
     unset [-f] [-v] [name ...]         until COMMANDS; do COMMANDS; done
     variables - Some variable names an wait [n]
     while COMMANDS; do COMMANDS; done  { COMMANDS ;
    

    use help <command>, f.e help shift to get more information about the commands.

    Bash on Mac OS X[edit]

    Bash on Windows[edit]

    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.