Real question being what is the purpose of running
:wq inside script ?
You wrote
Quote:
.....
Above command helps to save the file even if it open.
.....
Can you elaborate on this ?
How does
:wq make things work better or worse for file in question ?
There are other tools on your disposal such as
lsof or
fuser to see if the file is opened.
You can also use
screen or
tmux to achieve similar hackery, sending commands into sessions.
Check out
-X options and examples online.
But try to correct the workflow first and use other tools not editors in scripts in such way...
Can you show the code, perhaps a better way can be devised to make entire processing.
Hope that helps.
Regards
Peasant.