Solved

Last command in the UNIX shell prompt

Posted on 2011-03-19
8
568 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
 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

 

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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

617 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