UNIX equivalent to DOSEDIT ??

Alvin E. Sylvain asylvain at felix.UUCP
Sat Sep 29 08:54:38 AEST 1990


This is one of probably many responses, but I have also included a long
list of C shell history substitution commands that Unix netters may
find interesting (I hope).

In article <269 at cadlab.sublink.ORG> staff at cadlab.sublink.ORG (Alex Martelli) writes:
>phd_jacquier at gsbacd.uchicago writes:
>
>>Hi, 
>>I am a beginner at UNIX and have the following question.
>>Why is there not a simple way to recall, edit and reissue old commands
>>like in DOS with dosedit or scrollrecall, or in VMS ?
>
>I predict you'll get MANY answers to this... I'm answering anyway to
>pass the information that on Ultrix 4.0, the C shell (csh) has the
>command recall ability, e.g. press up arrow to see the last command
>you gave (and so up in the history), PLUS you can edit to your
>heart's content with a goody subset of vi.  In the previous release
>of Ultrix, you got this function in the unsupported "new C shell".
[ ... ]

Actually that sounds like Kornshell, which incidentally has a much
better history substitution mechanism.  BUT, you are more likely to
already have /bin/csh on your system.  You must take some action (buy?
scrounge?  forage?) to get /bin/ksh.

You probably can't get DOSEDIT syntax, but at least history substitution
of some kind is available.

First off, make sure you are running the C shell.  This can generally be
guaranteed on a permanent basis with the following command:

   chsh <your-user-name> /bin/csh

If this doesn't work, talk to your system administrator.

Standard csh history commands are summarized as follows:
(quoted and summarized from "The CSH Reference Guide",
A System Publication, 711 Chemeketa Dr, San Jose CA 95123
no association whatsoevery)

history          - print the current list of 'old' commands
set history=n    - tell the C shell to only remember n commands
                   (generally done in your .login file)

to get historical events:
!n      - execute command n
!-n     - execute command n relative to current command
!str    - command that begins with str
!?str   - command that contains str
!!      - previous command
^x^y    - substitute x for y on previous line

from previous command line, retrieve:
:0      - first word
:n      - argument n
:^      - first argument
:$      - last argument
:%      - word matched by ? search
:x-y    - range of words from x to y
:-y     - range of words from first to y
:*      - all args
:x*     - range of arguments from x to last
:x-     - range of words

from previous command, modify:
:ge     - return filename suffixes
:gh     - return root pathname
:gr     - return filename prefixes
:gs/x/y - substitute all occurances of x for y
:gt     - return tail pathname
:g&     - repeat previous substitution
:e      - return filename suffix of first argument
:h      - return root pathname of first argument
:q      - quote substituted words to prevent further substitution
:r      - return filename prefix of first argument
:s/x/y  - substitute first occurance of x for y
:t      - return tail pathname part of first argument
:x      - same as q except quote words individually
:&      - repeat previous substitution

Example:
You type in the command:
rm fred barney

You get the error message that fred and barney are unavailable for removal
(or some such).  You hit your head and say, "Oh, that's right ..."
Then you type:
!!:s/f/F/:s/b/B

the shell echoes (just so you know what you changed to)
rm Fred Barney

and removes the files Fred and Barney.

Quick analysis of above:
!!        previous command (as opposed to !56, which would be the 56th command)
:s/f/F/   change the first little f to a big F
:s/b/B    change the first little b to a big B

Another example:
rm Fred Barney

No no no, you already removed those two!  Weren't you following the
examples?  What you need now is to re-make them!! Type:
^rm^make

and you'll get:
make Fred Barney

and the make program is run to re-construct files Fred and Barney.

Have fun.
------------------------------------------------------------------------
"I got protection for my    |               Alvin "the Chipmunk" Sylvain
affections, so swing your   |   Natch, nobody'd be *fool* enough to have
bootie in my direction!"    |   *my* opinions, 'ceptin' *me*, of course!
-=--=--=--"BANDWIDTH??  WE DON'T NEED NO STINKING BANDWIDTH!!"--=--=--=-
--
------------------------------------------------------------------------
"I got protection for my    |               Alvin "the Chipmunk" Sylvain
affections, so swing your   |   Natch, nobody'd be *fool* enough to have
bootie in my direction!"    |   *my* opinions, 'ceptin' *me*, of course!
-=--=--=--"BANDWIDTH??  WE DON'T NEED NO STINKING BANDWIDTH!!"--=--=--=-



More information about the Comp.unix.shell mailing list