linux - 如何在shell脚本中调用vim?
PHP中文网
PHP中文网 2017-04-17 15:17:12
0
4
753

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

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

目前想到的是:

  • 在脚本中调用vim,但已有错误提示

  • 将新建文件的路径+名称返回给一个变量,然后用vim打开

我的问题是:

  • 脚本中能否调用vim?

  • 如何获取执行脚本的返回值?

  • 或者有其他的更好的解决方法?

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

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(4)
阿神

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 $?
小葫芦

I guess what you need is sed and awk.

巴扎黑

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. .

左手右手慢动作

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template