Link to home
Start Free TrialLog in
Avatar of Quark
Quark

asked on

DOSKEY in Bourne Shell??

Is there any command or build in function in the Bourne Shell that can perform the features same like MS-DOS's DOSKEY?

Or any other shell have this features?
ASKER CERTIFIED SOLUTION
Avatar of griessh
griessh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of interiot
interiot

Bash is used more often as a scripting shell, and Tcsh used more often interactively.

Tcsh by default supports up and down arrows for command history.  'history' can be used to view the history list.  !5 runs the fifth command in the history list.  Macros are called aliases, and can be set by typing "alias c clear".

So I'd recomend that you change your shell to tcsh.  While that's a decision made more on personal taste, it's a decision that a lot of people have made.
I prefer bash for interactive use, rather than tcsh, but that's because I learned UNIX with the bash shell. Bourne Shell is the original shell /bin/sh and as far as I know has no history mechanism. Bash stands for Bourne Again Shell, and is much nicer to use than sh.
marecs, you are right about bash's advantages. My path was sh->csh->ksh (never used tcsh, always liked bash).

======
Werner
Avatar of Quark

ASKER

Thank you every body.

Yes. What I am looking for is the Command History browse with the up/down arrow keys together with the left/right
arrow keys.

How to change to other shell? So far I just familiar with Bourne Shell only.
1) Ask you sys admin to switch you over to another shell
You will have to learn how to use your new shell.

2) To switch to ksh, you have to have the ENV variable
exported that points to script to set all your environment. I usually set it:

export ENV=$HOME/.env

where .env contains at a minimum the above mentioned entries. You thenjust run "ksh" and you will open a new shell that allows you to browse your history.

Anyhow, if you are not familiar with these shells, it would be wise to learn about their advantages/disadvantages and how to start them.

Good luck

======
Werner
Looks a bit odd:

When you open a ksh, it will scan the ENV variable and execute the script it points to.
When you have ksh as your login shell, it will ource the $HOME/.profile first. That's where you can set your terminal settings etc.

If you want to use ksh, let me know, I'll give you some pointers.

======
Werner
Avatar of Quark

ASKER

OK thank you
Now my profile can switch to Korn Shell (ksh) already.
But is it the only way to perform command history in ksh?How about other shells? How about AWK? C Shell?
csh has a history. you use the "!" to recall commands, but you have to know which command you want, so you have to display the history list most of the time ... not as convenient as in other shells. The modern shells all have some type of history, but I am really mostly familiar with the ksh.

ksh keeps a .history file that you can setup in size. You can look at the commands using the 'history' command. (history -11 displays the last 11 commands, history 3-7 from command 3 to 7, history 11 from 11 on). You can run the commands using "r", like "r 4" will run command 4 from the history. to run the last command that started with 'de' do a "r de" (very useful!). With the "set -o emacs" you configure the editor style to move in the history list. ksh is using the HISTFILE variable to point to the history file. If it doesn't exist, it will craete a temp one for you. There is also HISTSIZE variable that sets the number of commands that go in the list, but I think that goes to far now. If you intend to use ksh more frequently, I suggest to get the book "The New Kornshell" by M.I.Bolsky and David.G.Korn (about $42). It is a good reference and learning tool for ksh.

Good luck

======
Werner
Avatar of Quark

ASKER

How to keyin this in ksh?

set -o emacs
alias __A ^P
alias __B ^H
alias __C ^F
alias __D ^B

__A    <- how to key in? is it underscore then A?
^P     <- how about this? is it Ctrl + P?


Is it store it in .profile also?

.profile is executed at login only. The file pointed to in ENV is used each time you open a shell. So I would suggest:
1) do a "setenv ENV=$HOME/.env" in your current shell.
2) create a .env file in your home directory and add the lines from above. (Yes, __A is underscore,underscore,A; ^P is Control P).
3) run "ksh", that should do the trick!

======
Werner
> How to change to other shell?
most modern UNIX/Linux support the chsh command which allows to change your login shell.
If this is not possible and your admin won't do, you may
try following in your ~/.profile:

    exec /usr/bin/bash

Keep in mind that depending on the shell (bash in my example), you need to prevent this exec call in subsequent calls (infinite loop !)

To use the history with the cursor keys in bash, you need to set following environment variables (for example in
~/bashrc):
   HISTFILE=
   HISTFILESIZE=
   HISTSIZE=

The history in ksh is enabled using
   set -o vi
or
   set -o emacs
than you can scroll the histor using the appropriate key-sequences (vi- or emacs-like, but now DOSKEY-like)
 
 
In tcsh you need to set the shell variable:
   history =
some other nice variables are:
   histdup, sahehist, edit, autcorrect, correct