Is it possible to move a running script to a background shell?
The use of "move" is confusing. You mean some other verb, very probably (I can't guess which one). I'm taking it literally....
A shell script is just a file (not the same as a process interpreting that script, and you could have several processes - or none - running that script). You could move it (with
mv(1) or using rename(2) in some program) while it is running. But the shell interpreting it would have already some opened file descriptor on it, so that won't change anything. Actually, you don't want to move a script (and you don't move processes or jobs; however you can move files). The "move" verb is very confusing (at least to me, I am not a native English speaker) and I don't understand what and why you really want to do.
(a different question is what happens when you overwrite a script during its execution, but you don't ask that)
It looks like you want some program mimicking the action of a user inside a (pseudo-) terminal. Read the tty demystified page (terminals and pseudo-ttys are very complex, I forgot the details). Use expect to mimic a user inside a terminal.
BTW, managing passwords in scripts is risky (security holes are easy to make) and error prone, so smells really bad. I would try hard to avoid that, e.g. by using
ssh with public & private keys.
So better redesign your entire thing to avoid supplying passwords automatically (inside scripts).
You apparently want to do (but it is unclear to me if you want to do that yourself in your terminal, or from inside another script):
This is about job control. The fact that what goes in the background is a process running some shell interpreting a script or some other plain executable program is irrelevant. Unix shells are ordinary programs from the kernel's point of view. IIRC, job control is related to process groups.
In a comment, you mention connecting to some database. Most RDBMS client programs provide some way to give the password in a more appropriate manner (perhaps
mysql command). If you want to do that from another script some here document could be handy (that here document could contain or synthesize some SQL commands). Notice also that RDBMS systems won't alter their databases when authentication failed.
Can I run such commands inside a script?
I don't understand what commands (is it
bg %%) you want to run inside a script. If you want to drive job control from a script (but I believe you should not) then
expect is probably more suitable.
I want the script to start working like
nohup ./scripts.sh & but only after entering the correct password
That edit confuses me even more. What password are you talking about (I am not sure if your script provides a password to some RDBMS server, or requires one to be run completely)? I am guessing that you have some long-running script doing something related to databases (e.g. a backup lasting several hours). If that is indeed the case, you need to ask a different question. You could for example store the (interactively input) password somewhere and later run the backup in batch (perhaps using the
batch command with some here document). BTW, various RDBMS have different ways to provide the password and do the authentication so you really need to mention, in your future question, what actual RDBMS you are using.
So consider improving your question to motivate it a lot and give more context. I'm only guessing, and I could guess very wrong!
Or maybe you want the equivalent of daemon(3) in your shell? That would make yet another question (and since bash is free software, you can always patch it to add a new builtin inside it). I think (but I am not sure at all) that
exec shell builtin might be useful.