Solved

DOSKEY in Bourne Shell??

Posted on 2001-06-28
12
742 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now