• We did not send an email asking for donations - please read this post.

How to handle command line options after switching the user in script


Viswanath Ediga

Hello All,

I am writing a script where I need to switch to another user in the middle of the script. It goes as below
echo "$HOME"
echo $1
sudo su - oradev << \EOF
echo "$HOME"
echo $1

When I run the above script as "sh script_name hello" out put is as below

uid=5003(nagios) gid=5003(nagios) groups=500(dba),5003(nagios)
                           <####### I want my command line option,hello, to be echoed here as well 
uid=544(oradev) gid=500(dba) groups=500(dba)

our command line option, $1=hello, is working fine before switching the user, but for some reason it is not showing up after switching user.
I would be really happy if any one has any ideas on how to get this worked.

$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online

No members online now.

Latest posts