[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 777
  • Last Modified:

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?
0
Quark
Asked:
Quark
1 Solution
 
griesshCommented:
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
 
interiotCommented:
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
 
marecsCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

======
Werner
0
 
QuarkAuthor Commented:
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
 
griesshCommented:
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
 
griesshCommented:
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
 
QuarkAuthor Commented:
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
 
griesshCommented:
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
 
QuarkAuthor Commented:
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
 
griesshCommented:
.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
 
ahoffmannCommented:
> 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now