Attempting to use the 'script' command to save the session to a log. However when the command is used as the first line of the executable script, the script stops and won't proceed.
Essentially, this is correct behaviour. What's happening is that the 'script' command is spawning its own sub-shell underneath your current shell, and that's why you get a shell prompt and execution of the script does not continue. If you type 'exit' at that new prompt, the sub-shell will exit and the execution of the script will continue as normal past that point, albeit without being logged as a typescript.
If what you're actually wanting to accomplish is logging the output of a script, there's a few ways you could go about it, and the 'script' command isn't in fact the appropriate answer here.
If the script is non-interactive - that is, it requires no user input (and your provided test script looks like it doesn't) - then you could perhaps do something like this to log its output:
./script.sh | tee -a log.txt
The 'tee' command ensures that you still see the output of a script on standard output, but it also gets captured to a logfile (log.txt in the current directory, in this case). User inputs and certain other things won't get captured this way, but regular output will. This will make sure it goes to a file, and to the screen at the same time.
No. The script command can be used in a shell script as long as the user invoking the script directly interacts with whatever commands the script command runs OR your shell script redirects the input to the script command to complete whatever the script is running until the commands being run by script have terminated.