Quantcast
Channel: openSUSE Forums
Viewing all articles
Browse latest Browse all 40713

How to reference current User root when a script runs as root (su or sudo)?

$
0
0
Am modifying a script I found for another distro(Ubuntu). It mostly works but some behaviors seem to be different on openSUSE.

Scenario:
The script has to be run with root permissions (su or sudo).
References in the script cd to the logged in User typically with something like the following
Code:

cd ~/directoryname
Problem:
Whereas on Ubuntu the above code sets the directory to the home directory of the logged in User, on openSUSE it instead sets to root's home directory (because is running in the context of su or sudo).

Is there a simple solution?
Am considering stuff like declaring a variable with value of the current User's directory, then cd to that.

Code you think should work appreciated.

An alternative I've considered is to simply place all directories which normally would be in the User's home directory in root's home directory instead.

TIA,
TSU

Viewing all articles
Browse latest Browse all 40713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>