Quantcast
Channel: Using chown $USER:$USER inside bash script - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by Eric James Deiter for Using chown $USER:$USER inside bash script

$
0
0

When I calling my script with sudo it would set $USER to root.

$ sudo ./myscript.sh

I tried the chown ${USER:=$(/usr/bin/id -run)}:$USER /var/www/$sitename but it would still return root.

I found if I used who with awk I was able to get the current user that called the script with sudo.

currentuser=$(who | awk '{print $1}')}
chown -R $currentuser:$currentuser /var/www/$sitename`

Viewing all articles
Browse latest Browse all 6


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