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

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

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...

View Article



Answer by Andreas Bartels for Using chown $USER:$USER inside bash script

There is only a tiny fault I think. sudo opens a new shell for executing the command and after sudo the user is root. So maybe you should use something like this: MYUSER=$USER sudo chown...

View Article

Answer by marcosjsramos for Using chown $USER:$USER inside bash script

In order to simplify the problem and since your are getting the variable sitename, why don't you read a username variable? With that you'd make sure that the script execution is not dependent on the...

View Article

Answer by Tim Cutts for Using chown $USER:$USER inside bash script

If, for some reason, $USER is not set, you can use the id command to obtain the identity of the real user. So the first time you use the $USER variable, you can use the shell expansion to supply a...

View Article

Using chown $USER:$USER inside bash script

In a small bash script I'm running I am attempting to chown a new directory that is created. I've added: sudo chown $USER:$USER /var/www/$sitename sudo chmod 775 /var/www/$sitename after the line...

View Article


Answer by Hogcryat for Using chown $USER:$USER inside bash script

The accepted answer by @tim-cutts would not work if you call the script itself with sudo:sudo ./myscript.shA more simple version of this answer would be to use logname:curuser=$(logname)chown...

View Article
Browsing all 6 articles
Browse latest View live




Latest Images