Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Last command in the UNIX shell prompt

Posted on 2011-03-19
8
Medium Priority
?
570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

715 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