Bash() is superior to
sh() in most respects, but people don't realize it because they don't know what it's capable of. Just like the people that think
vi() is anywhere equal to
vim(), probably because they don't know about
Vimscript.
Here are some of the commands for manipulating the history that are exclusive to
Bash():
Code:
Commands for Manipulating the History
beginning-of-history (M-<)
Move to the first line in the history.
end-of-history (M->)
Move to the end of the input history, i.e., the line currently
being entered.
reverse-search-history (C-r)
Search backward starting at the current line and moving `up'
through the history as necessary. This is an incremental
search.
forward-search-history (C-s)
Search forward starting at the current line and moving `down'
through the history as necessary. This is an incremental
search.
non-incremental-reverse-search-history (M-p)
Search backward through the history starting at the current line
using a non-incremental search for a string supplied by the
user.
non-incremental-forward-search-history (M-n)
Search forward through the history using a non-incremental
search for a string supplied by the user.
...
yank-nth-arg (M-C-y)
Insert the first argument to the previous command (usually the
second word on the previous line) at point. With an argument n,
insert the nth word from the previous command (the words in the
previous command begin with word 0). A negative argument
inserts the nth word from the end of the previous command. Once
the argument n is computed, the argument is extracted as if the
"!n" history expansion had been specified.
yank-last-arg (M-., M-_)
Insert the last argument to the previous command (the last word
of the previous history entry). With a numeric argument, behave
exactly like yank-nth-arg. Successive calls to yank-last-arg
move back through the history list, inserting the last word (or
the word specified by the argument to the first call) of each
line in turn. Any numeric argument supplied to these successive
calls determines the direction to move through the history. A
negative argument switches the direction through the history
(back or forward). The history expansion facilities are used to
extract the last word, as if the "!$" history expansion had been
specified.
shell-expand-line (M-C-e)
Expand the line as the shell does. This performs alias and his-
tory expansion as well as all of the shell word expansions. See
HISTORY EXPANSION below for a description of history expansion.
history-expand-line (M-^)
Perform history expansion on the current line. See HISTORY
EXPANSION below for a description of history expansion.
...
insert-last-argument (M-., M-_)
A synonym for yank-last-arg.
operate-and-get-next (C-o)
Accept the current line for execution and fetch the next line
relative to the current line from the history for editing. Any
argument is ignored.
edit-and-execute-command (C-xC-e)
Invoke an editor on the current command line, and execute the
result as shell commands. Bash attempts to invoke $VISUAL,
$EDITOR, and emacs as the editor, in that order.
...
I use those on a daily bases when administering *nix systems. Can you do the job without them? Of course. But you can also eat soup with a fork. I chuckle every time I see someone leaning on their left- or right-arrow keys on the command line when making edits.
My favorite though is its ability to do history expansion:
Code:
HISTORY EXPANSION
The shell supports a history expansion feature that is similar to the
history expansion in csh.
...
Event Designators
An event designator is a reference to a command line entry in the his-
tory list. Unless the reference is absolute, events are relative to
the current position in the history list.
! Start a history substitution, except when followed by a blank,
newline, carriage return, = or ( (when the extglob shell option
is enabled using the shopt builtin).
!n Refer to command line n.
!-n Refer to the current command minus n.
!! Refer to the previous command. This is a synonym for `!-1'.
!string
Refer to the most recent command preceding the current position
in the history list starting with string.
!?string[?]
Refer to the most recent command preceding the current position
in the history list containing string. The trailing ? may be
omitted if string is followed immediately by a newline.
^string1^string2^
Quick substitution. Repeat the previous command, replacing
string1 with string2. Equivalent to ``!!:s/string1/string2/''
(see Modifiers below).
!# The entire command line typed so far.
Word Designators
Word designators are used to select desired words from the event. A :
separates the event specification from the word designator. It may be
omitted if the word designator begins with a ^, $, *, -, or %. Words
are numbered from the beginning of the line, with the first word being
denoted by 0 (zero). Words are inserted into the current line sepa-
rated by single spaces.
0 (zero)
The zeroth word. For the shell, this is the command word.
n The nth word.
^ The first argument. That is, word 1.
$ The last word. This is usually the last argument, but will
expand to the zeroth word if there is only one word in the line.
% The word matched by the most recent `?string?' search.
x-y A range of words; `-y' abbreviates `0-y'.
* All of the words but the zeroth. This is a synonym for `1-$'.
It is not an error to use * if there is just one word in the
event; the empty string is returned in that case.
x* Abbreviates x-$.
x- Abbreviates x-$ like x*, but omits the last word.
...
It's one of those things that if you don't know it exists, you don't miss it. But once you've used it, you get pissed off whenever you're stuck on a system that only has
sh().