Operating System - HP-UX
1833847 Members
2344 Online
110063 Solutions
New Discussion

Re: Bounre shell script help

 
windflower_1
Occasional Contributor

Bounre shell script help

Hey, I have trouble with one of my bourne shell script homework. Could anyone help me out? Any help appreciated.

The vi editor does not create backup copies as do some editors. If you edit a file and write the file to disk, you lose the orgial file. Write a Bourne shell script called "myvi" that will create a ".bak" file if you mkade any editing changes to the file while in vi.
windflowers
5 REPLIES 5
Michael Tully
Honored Contributor

Re: Bounre shell script help

 
Anyone for a Mutiny ?
Rajeev  Shukla
Honored Contributor

Re: Bounre shell script help

Just copy the file being edited..
#!/usr/bin/sh
if [ "$#" = "0" ] ; then
echo " Wrong Usage:
Please enter the file name to be edited:"
exit
fi
file=$1
cp $file $file.ori
vi $file

Use this script and see how it goes.
syntax to run is:
./myvi.sh
it copies file to file.ori and makes the changes to file.

Cheers
Rajeev
Sridhar Bhaskarla
Honored Contributor

Re: Bounre shell script help

Hi,

You will need to consider using "RCS" or "SCCS" for keeping revisions of files. Just create an archive of your file using the command "ci", check out the file using "co", use it. Once you are done with the changes, check it in back into the archive so that this copy will be safe. In case if you want to go back, you can always check out the previous version from the archive file.

You can keep revisions and can get the file of any date and anytime you want.

Look at "rcs" man page for more details.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
T G Manikandan
Honored Contributor

Re: Bounre shell script help

There is no need for anything special.

You can just use the "view" editor instead of "vi".

If you use view then the original file opened will be marked as readonly and you can make changes to the original file.

Revert
Wodisch
Honored Contributor

Re: Bounre shell script help

Hi,

if you are using the *classical* ZZ to save your files, your could simply put a "macro" into your "$HOME/.exrc" to save the old file first:

"this goes into your $HOME/.exrc
"comments after a quote are fine
map ZZ :!cp % %.org^V^M:wq^V^M
"the ^V^M is Ctrl-V, Ctrl-M

Well, the "map" line alone would be fine. Next time you start your "vi" and try to save something with "ZZ" (in commadn mode), you should get a the original move aside as "*.old".
You'll need write permission in that directory, though...

FWIW,
Wodisch
PS: maybe "vim" would be a better solution, I think you can instruct that to make a copy automatically...