Solved

Last command in the UNIX shell prompt

Posted on 2011-03-19
8
562 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 200 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysql between clause 2 21
winscp where are logs stored 3 34
Showing random records from database 10 36
INDEX does not make a difference, why? 10 44
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

813 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

18 Experts available now in Live!

Get 1:1 Help Now