Mohamed Saligh
Mohamed Saligh

Reputation: 12349

Unix shell script file to replace itself

I have a shell script (myfile.ksh) file which will have sequence of command. Somewhere there will be a command to replace this myfile.ksh with new file.

I studied that inside my myfile.ksh, I can start a new process with &.

. newfiletocopy.ksh &

I have put lot of effort to copy & replace the own file.

Is there any better way to achieve this?

Upvotes: 0

Views: 797

Answers (1)

Terrence M
Terrence M

Reputation: 2921

It is a little unclear what you want, but if you want to copy another file over the one currently being executed, adding something simple like this should work:

cp newfiletocopy.ksh $0

Upvotes: 2

Related Questions