Bash 脚本调用 vi 进行手动编辑,然后脚本恢复? [英] Bash script calls vi for manual editing, then script resumes?

查看:28
本文介绍了Bash 脚本调用 vi 进行手动编辑,然后脚本恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个创建文本文件备份的脚本,以及使用 SED 验证文本文件中某些语法的第二个脚本.

I wrote a script that creates a backup of a text file, and a second script that verifies some syntax in text file using SED.

中间有一个手动过程:用户编辑原始文件添加一些字符串.这个过程必须保持手动.

In the middle, there is a manual process: Users edit the original file adding some strings. This process must remain manual.

我想合并我的两个脚本,以便创建备份,为用户打开 vi,当用户完成编辑文件时,脚本继续执行语法验证.

I would like to merge my two scripts so the backup is created, vi is open for the user, when the user is done editing the file, the script resumes doing the syntax verification.

我在边做边学,但真的不知道如何编码打开vi,等待用户进行编辑,控制并通过验证恢复"部分.

I am learning by doing, but really do not know how to code the "open vi, wait for the user to do his editing, take control over and resume with verification" part.

我读到有一个名为 system(在 Perl 中)的函数可以使用,但我的代码是在 BASH 中.

I read there is a function called system (in Perl) that could be used, but my code is in BASH.

有关如何在 BASH 中完成此操作的任何建议?谢谢!

Any suggestions on how to get this done in BASH? Thanks!

推荐答案

bash 中,每条语句本质上就像对 system 的隐式调用(除非它是内置 shell命令),因为 shell 脚本旨在让运行其他程序更容易.

In bash, each statement is essentially like an implicit call to system (unless it's a builtin shell command) since shell scripts are designed to make it easy to run other programs.

backup some_file.txt
vi some_file.txt  # The script blocks until the user exits vi
verify_syntax some_file.txt

使用 vi 和像 ls 这样的命令的唯一区别是 ls 会做它的事情并在没有用户干预的情况下退出,而 vi(或任何交互式命令)将一直运行,直到用户明确退出.

The only difference between using vi and a command like ls is that ls will do its thing and exit without user intervention, while vi (or any interactive command) will run until the user explicitly exits.

这篇关于Bash 脚本调用 vi 进行手动编辑,然后脚本恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆