0

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

#!/bin/sh  
su rt  
PATH='/usr/local/rt/etc'  
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.

mforsetti
  • 2,666
  • 2
  • 16
  • 20

1 Answers1

0

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

#!/bin/sh
RT_ETC=/usr/local/rt/etc
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"

mikem
  • 418
  • 2
  • 7