bash.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 10 Feb 2018 01:36:16 +0200
changeset 2229 1a0b6597e594
parent 2228 837f1337c59b
child 2256 0ac7d9a3d658
permissions -rw-r--r--
Mark block quot in HTMLe.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1069
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
.. -*- coding: utf-8; -*-
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
=======
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
 Bash.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
=======
1346
a2fbf50a43f4 Fix: Has no 'contents::' directive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1334
diff changeset
     6
.. contents::
1905
fba288d59662 Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1346
diff changeset
     7
   :local:
1069
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
How override PS1, PS2?
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
======================
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
When loading bash read ~/.bash_profile and ~/.bashrc.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
Put at end of these files::
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
  PS1='\u@\H$ '
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
When xterm start bash - it start as non-login. So ~/.bash_profile and ~/.bashrc
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
didn't read. To workaround this use::
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
  $ xterm -e bash -i -c "mc -x"
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
That make bash interactive and init file was readed.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
Command history.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
================
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
Bash allow accessing to command that you type previously. There are several
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
options to control command history behavior. Set corresponding variables in
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
your ~/.bashrc file (which is read by interactive shell)::
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
  #   ignorespace do not save lines that start with space
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
  #   erasedups all previous lines matching the current line to be removed from
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
  #             the history list before that line is saved
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
  export HISTCONTROL=igrorespace:erasedups
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
  export HISTIGNORE=" ?cd *":"e *":"sudo mv *":"sudo rm *":"sudo cp *":"sudo mkdir *":"sudo chmod *":"sudo chown *":ls:pwd:"vlc*"
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
There are another options, with default values (which satisfy my needs, so
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
I don't put they to ~/.bashrc)::
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
  export HISTFILE=~/.bash_history  # where is command history stored
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
  export HISTFILESIZE=500          # how many lines been in $HISTFILE
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
  export HISTSIZE=500              # how many lines been stored in bash process
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
mc (GNU Midnight Commander).
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
----------------------------
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
You can also set special history rules for mc subshell in ~/.mc/bashrc file.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    49
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
Bash history.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
=============
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    53
http://wiki.bash-hackers.org/scripting/bashchanges
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    54
  This article is an incomplete overview of changes to Bash over the time.
1069
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    55
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56