How do I launch an editor from a shell script?

前端 未结 7 598
野性不改
野性不改 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:24

    Had the same trouble with 'pinfo' in a shell script 'while' loop. The line can be used in the script, it uses 'ps' to find the tty of the current process number, "$$", and stores that tty in $KEY_TTY:

      KEY_TTY=/dev/`ps | grep $$ | tr -s '[:blank:]' | cut -d " " -f 3`
    

    Later in the script, just call the tty-only proggie, with $KEY_TTY as input, in my case it was:

      pinfo -m $s $page < $KEY_TTY
    

    For 'vi' it'd be:

      vi $a < $KEY_TTY > $KEY_TTY
    

    The advantage is that the script as a whole can still accept STDIN input, and 'vi' (or whatever) should work fine -- without having to remember to set any environmental variables before running the script.

提交回复
热议问题