'How do I make a bash script interactive midway?

#!/bin/bash
testfunc()
{
    # test function
}
testvar="test"

# some setup
bash # I get a shell here but with no access to testfunc and testvar
# some cleanup

This script stops and opens a shell, and I can exit to continue execution. However the environment is not preserved, so I can't call the functions, variables etc. set by the script and vice versa. How do I get a shell in a way that does?



Solution 1:[1]

You can use export

#!/bin/bash
testfunc()
{
    # test function
}
testvar="test"

# some setup
export -f testfunc
export testvar
bash
# some cleanup

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alecxs