Esteban Rodriguez Esteban Rodriguez - 1 year ago 85
Bash Question

Error when using exec vi


if [ $# -ne 1 ]
echo "USAGE:vitest filename"


exec vi $FILENAME <<EOF
Line 1.
Line 2.


exit 0

I'm trying to input the Line 1. and Line 2. with Exec vi using the here doc, and commands.

When running the script it gives me the following:

Vim(?):Warning: Input is not from a terminal
Vim: Error reading input, exiting...

Press ENTER or type command to continueVim: Finished.
Vim: Error reading input, exiting...

Vim: Finished.

Answer Source

You want to start vi in ex mode, with a few minor changes to the script.

vi -e "$FILENAME" <<EOF
Line 1.
Line 2.

exec is almost certainly unnecessary, especially since you have an exit command following vi. exec is used to replace the current script with the given command; it is not needed simply to execute a command.

A brief history of UNIX text editors:

  • ed was the original editor, designed to work with a teletype rather than a video terminal.
  • ex was an extended version of ed, designed to take advantage of a video terminal.
  • vi was an editor that provided ex with a full-screen visual mode, in contrast with the line-oriented interface employed by ed and ex.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download