bash.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sun, 18 Oct 2009 13:48:19 +0300
changeset 221 97171c12b447
parent 27 99584256fa88
child 276 ed6b5ae36a49
permissions -rw-r--r--
About command history.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
-*- outline -*-
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
* How override PS1, PS2?
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
When loading bash read ~/.bash_profile and ~/.bashrc.
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
Put at end of these files
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
  PS1='\u@\H$ '
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
221
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    11
When xterm start bash - it start as non-login. So ~/.bash_profile and ~/.bashrc
27
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
didn't read. To workaround this use
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
  $ xterm -e bash -i -c "mc -x"
99584256fa88 How override PS1, PS2.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
221
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    16
That make bash interactive and init file read.
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    17
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    18
* Command history.
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    19
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    20
Bash allow accessing to command that you type previously. There are exist
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    21
several options to control command history behavior. Set corresponding
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    22
variables in your ~/.bashrc file (which is read by interactive shell):
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    23
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    24
  #   ignorespace do not save lines that start with space
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    25
  #   erasedups all previous lines matching the current line to be removed from
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    26
  #             the history list before that line is saved
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    27
  export HISTCONTROL=igrorespace:erasedups
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    28
  export HISTIGNORE=" ?cd *":"e *":"sudo mv *":"sudo rm *":"sudo cp *":"sudo mkdir *":"sudo chmod *":"sudo chown *":ls:pwd:"vlc*"
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    29
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    30
There are another options, with default values (which satisfy my neediness, so
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    31
I don't put they to ~/.bashrc):
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    32
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    33
  export HISTFILE=~/.bash_history  # where is command history stored
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    34
  export HISTFILESIZE=500          # how many lines been in $HISTFILE
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    35
  export HISTSIZE=500              # how many lines been stored in bash process
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    36
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    37
** mc (GNU Midnight Commander).
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    38
97171c12b447 About command history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 27
diff changeset
    39
You can also set special history rules for mc subshell in ~/.mc/bashrc file.