[plug] Anyone got bash tips for an old korn shell user?

Steege, Phil E phil.e.steege at lmco.com
Wed Sep 4 21:10:08 WST 2002


Here is an excerpt from
www.gnu.org/manual/bash-2.05a/html_node/bashref_88.html#SEC95 

Readline provides commands for searching through the command history (see
section 9.1 Bash History Facilities) for lines containing a specified
string. There are two search modes: incremental and non-incremental. 

Incremental searches begin before the user has finished typing the search
string. As each character of the search string is typed, Readline displays
the next entry from the history matching the string typed so far. An
incremental search requires only as many characters as needed to find the
desired history entry. To search backward in the history for a particular
string, type C-r. Typing C-s searches forward through the history. The
characters present in the value of the isearch-terminators variable are used
to terminate an incremental search. If that variable has not been assigned a
value, the ESC and C-J characters will terminate an incremental search. C-g
will abort an incremental search and restore the original line. When the
search is terminated, the history entry containing the search string becomes
the current line. 

To find other matching entries in the history list, type C-r or C-s as
appropriate. This will search backward or forward in the history for the
next entry matching the search string typed so far. Any other key sequence
bound to a Readline command will terminate the search and execute that
command. For instance, a RET will terminate the search and accept the line,
thereby executing the command from the history list. A movement command will
terminate the search, make the last line found the current line, and begin
editing. 

Readline remembers the last incremental search string. If two C-rs are typed
without any intervening characters defining a new search string, any
remembered search string is used. 

Non-incremental searches read the entire search string before starting to
search for matching history lines. The search string may be typed by the
user or be part of the contents of the current line. 


-----Original Message-----
From: Colin Muller [mailto:colin at twobluedots.com.au] 
Sent: Wednesday, September 04, 2002 8:44 AM
To: plug at plug.linux.org.au
Subject: Re: [plug] Anyone got bash tips for an old korn shell user?


> So can anyone point me to a tutorial (or even just tell me) that will 
> explain how to find a previous command (let's say, a mount command), 
> scroll through all previous mount commands to find the one I want, 
> edit it to what I want now, and not have it execute until I press 
> enter?  It shouldn't be hard, I keep hearing how easy bash is to 
> use...

Ctrl-r

Then type what you're after, like mount

If the first one which appears is not right, type Ctrl-r repeatedly to
scroll through previous commands which also contained the characters you
typed.

Then press enter to execute the command, or:
When you get to a previous command you want to edit, type an editing key
sequence and you'll be dropped to the command line with that editing command
already performed, ready to edit the line further,
e.g:
Ctrl-a - go to start of line
Ctrl-e - go to end of line
Ctrl-d - delete character under the cursor
Alt-b - back a word
Ctrl-c - drop to empty command line (the one you were on from Ctrl-r will be
placed on the line above the prompt)

etc etc. Searching google for ctrl-r bash will get you some tips pages for
these key sequences.

Oddly, there doesn't seem to be a way to scroll forwards again if you go one
too far back with Ctrl-r; or maybe I'm just showing my ignorance there.

Colin



More information about the plug mailing list