Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Last command in the UNIX shell prompt

Posted on 2011-03-19
8
Medium Priority
?
573 Views
Last Modified: 2012-06-27
In UNIX shell prompt what key do I need to type to get the last command executed?

If I press arrow it writes these characters on the prompt: ^[[A
# echo $SHELL
/sbin/sh
# ^[[A
^[[A: not found
#

0
Comment
Question by:toooki
8 Comments
 
LVL 12

Expert Comment

by:larsrohr
ID: 35174116
/sbin/sh doesn't maintain a command history for you to scroll back through.

You can change your default shell to bash or tcsh, which both use the arrow keys for stepping through command history.  Or you could just type 'bash' to startup the shell for your current session; then any commands you do once bash is started can be stepped through with the arrow keys.
0
 
LVL 5

Expert Comment

by:paulqna
ID: 35174861
If your /sbin/sh supports it then "fc -l" is a good start.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35174907
If your /sbin/sh is indeed a link to ksh, you could do this:

Add to your $HOME/.profile or to /etc/profile

alias __A=$(echo "\020")   # up arrow = ^p
alias __B=$(echo "\016")   # down arrow = ^n
alias __C=$(echo "\006")   # right arrow = ^f
alias __D=$(echo "\002")   # left arrow = ^b

and

set -o emacs

Now logout, login again and retry.

wmp
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 

Author Comment

by:toooki
ID: 35177736
Thank you for all your help.

How do I switch "default shell to bash"? Could it be done in .profile file.

/bin/bash takes me to the bash profile where arrow keys works. But after switching to bash none of my aliases work.

yes I set fc -l for history but just wanted to reduce my time for commands -- if I make a spelling mistake in a huge command I need to retype that again --- arrow key could save the time.

I set these entries in .profile file but arrow keys did not work after that (I logged out and logged back in)

alias __A=$(echo "\020")   # up arrow = ^p
alias __B=$(echo "\016")   # down arrow = ^n
alias __C=$(echo "\006")   # right arrow = ^f
alias __D=$(echo "\002")   # left arrow = ^b
set -o emacs
0
 
LVL 12

Expert Comment

by:larsrohr
ID: 35177766
Which distribution of unix/linux are you using?  Solaris?

Some distros have a 'chsh' command for changing your shell -- but for user 'root', you really want to stick with a rather plain shell, one that has few dependencies and can be counted on to work when all else is failing.

Since it appears that you are dealing with a root user, I would suggest that you leave the default shell for 'root' as /sbin/sh, and instead make your aliases work for you when you manually invoke /bin/bash.  Where do you currently define your aliases?  If you add them to ~/.bashrc, you may just solve your problem.
0
 

Author Comment

by:toooki
ID: 35177815
Thank you.

# uname -a
SunOS halter37 5.8 Generic_108528-29 sun4u sparc SUNW,Ultra-5_10

So it is Solaris 8.

When I become root I type in . /home/mylogin/.profile to use my aliases. As root profile does not have any aliases.
I define all my aliases in .profile file.
In the .profile file I also have this line:
ENV=$HOME/.kshrc
export ENV

I defined the aliases alias __A=$(echo "\020")   # up arrow = ^p in the .profile file but that did nit work.
0
 
LVL 12

Accepted Solution

by:
larsrohr earned 800 total points
ID: 35177984
OK, then.  I would recommend that you don't change the root default shell.

When you become root, then you can start bash, and then load your aliases into your bash shell:

# bash
# . /home/mylogin/.profile

Doing it this way, you shouldn't need that up arrow definition, since that's built in to bash.
0
 

Author Comment

by:toooki
ID: 35178070
Thank you.

Thank you all for help.

# bash
# . /home/mylogin/.profile

The above worked perfectly.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Fine Tune your automatic Updates for Ubuntu / Debian
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

885 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