Home  >  Q&A  >  body text

linux - 如何在shell脚本中调用vim?

想要写个脚本,执行后进入到vim文本编辑界面

例如, 脚本名叫wt, 在脚本中我创建了一个文件123.txt, 如何在脚本执行完成后进入到对123.txt的vim编辑界面

目前想到的是:

我的问题是:

刚开始学shell,希望大家能给个解答或者是推荐些相关的资料,拜谢!

PHP中文网PHP中文网2741 days ago704

reply all(4)I'll reply

  • 阿神

    阿神2017-04-17 15:19:12

    I don’t know if I can help LZ

    1. New file

      vi wt
    2. Edit the file, copy the following code into the wt file, save and exit

      # Status, 123: success, 0: error
      status=123
      vi 123.txt
      exit $status

      Note: The last line specifies the exit status of the shell script. The status value of 123 is only for demonstration

    3. Give permission

      chmod +x wt
      ll | grep 'wt'
    4. Execute

      ./wt
    5. View execution status

      echo $?

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 15:19:12

    I guess what you need is sed and awk.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 15:19:12

    Vim can be called in the script, but you can only play with the parameters. .
    The return value of the script can be obtained using $?
    I don’t understand what you want to do. Is it just to open a file for editing with vim?
    Shell allows you to check information online. You can search a lot on Baidu and Bing. .

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 15:19:12

    What you mean by this is that after the script is executed, you can enter vim to edit the files you created in the script, right? You no longer need to enter vim on the command line

    reply
    0
  • Cancelreply