hey friends,

I m in a process of automating Sudo test plan, where i need to invoke another shell within a shell automatically, then need to append a line into that script in sub-shell, then save it and quit from it..all automatically.
I m able to do evrything but not able to automate the process of saving and quiting from the sub-shell.

Is there any way to automate the "SAVE AND QUIT" [ :wq! ] process.?

10 Years
Discussion Span
Last Post by ghostdog74

It looks like you're trying to automate vi.

There are such things as "ed scripts" - scripts that invoke the ed editor.
You can use that scripting language easily. vi presents problems because it expects the terminal to be a tty, ed doesn't. Your stdin is a shell script.

man ed


Hey Jim,

thnx for the reply.
But the point is i need to do the sutomation in Vi only..!!
and still looking for the solution..!!

Anyways..i m still hopeful to find sm way out for this.
If u come across any sol. for this in Vi ...plz reply..!



why only vi? from the way i see, you just need to do something to a file and save it. So you can also use sed/awk to do the job.
If you still want to try vi, here's one way, not the best, but still does something.

sun# echo "test" > file
sun# more file
sun# vim -c "%s/test/changed" -c ":wq" file
sun# more file
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.