How to execute previous command in UNIX?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to execute previous command in UNIX?
# 1  
Old 06-18-2015
How to execute previous command in UNIX?

Hi,

I was able to use
Code:
!!

on the console.

But when I used
Code:
 !!

in the run.sh, it says something like command not found.
# 2  
Old 06-18-2015
Command line editing mode in a shell only works in interactive mode; not in a shell script. The characters used to rerun a command vary from shell to shell and within a shell from editing mode to editing mode.

I tend to prefer vi line editing mode and I usually use the Korn shell (vi line editing mode is also available in any other shell that conforms to the POSIX standards when you are not using a block mode terminal or terminal emulator). You obviously prefer a different line editing mode. (You can check the description of the shell set -o option built-in on the man page for your shell to see which, if any, line editing modes your shell provides.)
# 3  
Old 06-18-2015
History substitution is not turned on on non-interactive shell for good reason.
If you must know:
Code:
set -o history
set -o histexpand


If you want to repeat the previous command, save it in a var.
# 4  
Old 06-18-2015
Executing a previous command in a script is just copy-and-paste of that line in your editor. Or are you talking of a interactive input to the script that should be repeated? Then, as Aia said, save it, and extend your script by a small exclamation mark handler.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Command to print previous year in UNIX

hi all, I use date +%Y which gives Current year. Requirement: I want previous year to be printed. Please help me. Note: I tried date +%d/%m/%Y -d "-1 years" which is not working. (10 Replies)
Discussion started by: wasim999
10 Replies

2. UNIX for Dummies Questions & Answers

Execute a command in different directory through Unix Script

Hi Gurus, I have the below requirement, Execute an unix script which will pick the latest file from the archive directory and do a grep (on multiple patterns) on that file. processingDir="/usr/apps/irdc/informatica/spsf_sales/TgtFiles/ARCHIVE" filename = 'ls Check* | sort -n -k 2 |... (6 Replies)
Discussion started by: diva_thilak
6 Replies

3. Shell Programming and Scripting

How to execute PMCMD command in Unix?

Hi All, I am trying to run the PMCMD commend to execute the informatica workflow but while executing from my home directory i am getting below error ksh: pmcmd: not found I executed from my server/bin directory too. I am getting the same error. My commend is: pmcmd startworkflow -sv... (3 Replies)
Discussion started by: kannansr621
3 Replies

4. Shell Programming and Scripting

Execute a unix command

Hi, Please suggest me to execute unix command. Input : 2011-01-01 00:00:00 Required output : 20110101000000 YYYYMMDDHH24MISS Regards Akshu (4 Replies)
Discussion started by: akshu.agni
4 Replies

5. Shell Programming and Scripting

Execute unix command from an html page in windows

i have a problem situation, where i have a html file say click.html. i have a button "ls" in that html page. i run this html file in windows....Now say if i click that "ls" button it must connect to the unix server and execute ls and return the results back to html page in windows. can anyone tell... (8 Replies)
Discussion started by: niteesh_!7
8 Replies

6. UNIX for Dummies Questions & Answers

How to execute a command on UNIX?

Hi guys, I'm completely new to UNIX and Linux and all that stuff. I've been using webhosting (shared) for some time years now and recently I've wanted to carry out some tasks that have had some commands which are not familiar to me. One was to install Mailman and the other to copy files from one... (6 Replies)
Discussion started by: BenA
6 Replies

7. Programming

execute unix command from java eclips

Hi all, I tried to execute the command by 2 ways : 1) Java Runtime class exec method - but the problem there is that it only can execute scripts without arguments(I need with args) 2) the Jtux classs Uprocess- the problem it is not supported by windows and my eclips platform is on... (0 Replies)
Discussion started by: katzs500
0 Replies

8. UNIX for Dummies Questions & Answers

Repeat previous unix command

Hi all, Is there a way to bring back the previous unix command without retyping? I tried the "arror up" key, and it seems not working (sun solaris). What is the correct way? Thanks! (4 Replies)
Discussion started by: syang68
4 Replies

9. UNIX for Dummies Questions & Answers

previous,next command in unix

Hi , after pressing down arrow,up arrow I want to find previous,next command in unix wat can i do for tat plz tell me I am accesing unix server thru telnet. my shell prompt ksh (4 Replies)
Discussion started by: arulkumar
4 Replies

10. Shell Programming and Scripting

execute command unix with java:possible or not?

hi everybody, i have a small unix script and i want to use it with java, so how can i executte unix command with java (if it is possible): in fact i want to use some values returned by this script with java swings. is it possible (of course everything is possible) but how can i do? thank you in... (4 Replies)
Discussion started by: mips
4 Replies
Login or Register to Ask a Question