Bash script calls vi for manual editing, then script resumes?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 17:10:45

问题


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.

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.

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.

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

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


回答1:


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

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.



来源:https://stackoverflow.com/questions/31686006/bash-script-calls-vi-for-manual-editing-then-script-resumes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!