How to switch user using shell script ?

Hi,

script1.sh
script2.sh
script3.sh

From above, script1.sh is the main script which is executed from root user, creates installation directory, changing ownership and execution rights etc..etc.. and finally calls scripot2.sh and script3.sh to create the database as well as for post database creation steps respectively.

script2 & script3 contains database creation statement and other oracle DDL statements in it which should be get executed from 'oracle' user.

But as the main script is running from 'root' user, so how to switch to 'oracle' user dynamically within the shell script itself ?

If your parent script is invoked as root the you can invoke the command or script as different user.
su <user> script/command
Example:
su oracle script2.sh
or
su admin script3.sh
or
su test "touch /tmp/one.txt"

Thanks,
Kalai