0

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?

1
  • 1
    It is really hard to tell what you are trying to accomplish. Consider editing your question to show a 'use-case' for how and why you need a "unix shell script file to replace itself". Show 1. what you type on the command line, what happens in step 2, step 3, .... etc. The '&' only says, run the current command in the background and go to the next line in the script, execute that cmd without waiting for the backgrounded command. There is also exec, but it is for advanced usage. If you can't describe in simple language what use-case requirement is, you probably don't need exec. Good luck! Commented May 25, 2012 at 3:49

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.