Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I launch an editor from a shell script?

Tags:

I would like my tcsh script to launch an editor (e.g., vi, emacs):

#!/bin/tcsh
vi my_file

This starts up vi with my_file but first displays a warning "Vim: Warning: Output is not to a terminal" and my keystrokes don't appear on the screen. After I kill vi, my terminal window is messed up (no newlines), requiring a "reset". I tried "emacs -nw", "xemacs -nw", and pico with similar results. "xemacs" works but launches a separate window. I want to reuse the same terminal window.

Is there a way to launch an editor from a script so that it reuses the same terminal window?

like image 413
Marc Eaddy Avatar asked Nov 06 '09 20:11

Marc Eaddy


People also ask

How do I get the output of a shell script?

To store the output of a command in a variable, you can use the shell command substitution feature in the forms below: variable_name=$(command) variable_name=$(command [option ...] arg1 arg2 ...) OR variable_name='command' variable_name='command [option ...] arg1 arg2 ...'


1 Answers

I answered my own question! You have to redirect terminal input and output:

#!/bin/tcsh
vi my_file < `tty` > `tty`
like image 173
Marc Eaddy Avatar answered Oct 10 '22 15:10

Marc Eaddy