Solved

Last command in the UNIX shell prompt

Posted on 2011-03-19
8
558 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

707 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

20 Experts available now in Live!

Get 1:1 Help Now