bash.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 22 Feb 2016 12:41:52 +0200
changeset 1903 901e7394849f
parent 1346 a2fbf50a43f4
child 1905 fba288d59662
permissions -rw-r--r--
Decrease intent to increase space usage on mobile.
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; -*-
1334
9bf0d5a1f0cf Include common header with quick links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1069
diff changeset
     2
.. include:: HEADER.rst
1069
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
=======
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
 Bash.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
=======
1346
a2fbf50a43f4 Fix: Has no 'contents::' directive.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1334
diff changeset
     7
.. contents::
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
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
  http://wiki.bash-hackers.org/scripting/bashchanges
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
                This article is an incomplete overview of changes to Bash over
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    55
                the time.
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56
2a7388c5fef2 Bash history.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    57