How do I launch an editor from a shell script?

前端 未结 7 477
野性不改
野性不改 2021-02-04 03:44

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 w

7条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 04:47

    The reason you're getting the error is that when you start a shell in your environment, it's starting in a subshell that has STDIN and STDOUT not connected to a TTY — probably because this is in something like a pipeline. When you redirect, you're opening a new connection directly to the device. So, for example, your command line turns

    $ vi < `tty` > `tty`
    

    into

    $ vi < /dev/ttys000 > /dev/ttys000
    

    So you're not really using your old STDIN/STDOUT, you're creating two new files and mapping them to your vi process's STDIN/STDOUT.

    Now, tell us what you're doing with this and we'll tell you how to avoid this kludge.

提交回复
热议问题