Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to write a script but I'm stuck here. See the code please!

aug@august:~/play$ for i in {1..100..4}
> do
> echo "august"
> touch august $i+$2
> mkdir dir

Is there any way to go previous line? I mean there was a mistype, I did in touch august $i+$2. Ipressed ENTER key, so I went for new line. How can I get back to previous line?

share|improve this question
    
you should write script in a file then run it from terminal. You can also use UP key for previous command, but no way to revert the command. –  shantanu Sep 8 '12 at 7:40
add comment

2 Answers

up vote 1 down vote accepted

bash's command-line editor doesn't support this, either do as anwar suggests or keep everything on one line separated by semicolons or put it into a script file.

On a side note, zsh has features that help with this. The zsh line editor (zle) is a more fully featured editor and supports moving within a multi-line command. When the command becomes too long to handle in zle it has a builtin feature, edit-command-line, which opens up the command-line in your favorite editor. It's usually not bound, try with:

bindkey "^[e" edit-command-line

Alt-e should now activate it, save and quit to go back to the command-line.

share|improve this answer
add comment

After you pressed Enter and got an error message, you can just go back in history:

Just press the key in your keyboard to fix the typo. If you press key the terminal will show you this line:

for i in {1..100..4}; do echo "august"; touch august $i+$2; mkdir;

Correct the mistyped stuff around touch august $i+$2 and add a done at the end of the command.

Then hit the Enter key. This should solve your problem.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.