Solved

DOSKEY in Bourne Shell??

Posted on 2001-06-28
12
750 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:Quark
12 Comments
 
LVL 11

Accepted Solution

by:
griessh earned 50 total points
ID: 6235066
What Doskey feature are you thinking of? The command history?

In ksh just

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

and you will have a history you can browse with the up/down arrow keys and in a line with the left/right arrow keys.

Hope that answers your question. If not, please give us some clarification.

======
Werner
0
 
LVL 3

Expert Comment

by:interiot
ID: 6235221
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.
0
 
LVL 5

Expert Comment

by:marecs
ID: 6235323
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.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 11

Expert Comment

by:griessh
ID: 6235342
marecs, you are right about bash's advantages. My path was sh->csh->ksh (never used tcsh, always liked bash).

======
Werner
0
 

Author Comment

by:Quark
ID: 6236392
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.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6236414
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
0
 
LVL 11

Expert Comment

by:griessh
ID: 6236416
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
0
 

Author Comment

by:Quark
ID: 6236617
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?
0
 
LVL 11

Expert Comment

by:griessh
ID: 6237873
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
0
 

Author Comment

by:Quark
ID: 6238885
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?

0
 
LVL 11

Expert Comment

by:griessh
ID: 6238981
.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
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6241186
> 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
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question