im not familiar in shell scripting but im trying to achieve at least this script but my problem is once superuser rt is done logging in it brings me to this

[rt@superuser root]$

instead of reading the second line, i would like to achieve at least something like this

[rt@superuser etc]$

etc is the directory that i need to be in and not the root. below are my command line in shell script

su rt  
cd ${PATH}

how can i make a shell script that need to super user first then automatic change its directory once login in super user.


Don't put su in the script. Run the script after you su...

cd ${RT_ETC}

$ su rt
[rt@superuser root]$ /path/to/my/script

Of course, if your goal is just to be in the /usr/local/rt/etc directory when you become the rt user, simply add the cd to the .bashrc and it will happen whenever you login and source the shell profile (ie. su - rt)

As an aside, I would recommend against using PATH in the way you have used it. PATH is a system variable that has very specific meanings. Best not to mess with it like that. Better to use another variable... ie. RT_ETC

FYI- su is "switch user" not "superuser"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.