Using chown in a script

Johnny Rosenberg gurus.knugum at gmail.com
Sun Sep 5 15:16:58 UTC 2010


Den 5 september 2010 17:02 skrev Gurus Knugum <gurus.knugum at gmail.com>:
> I copy some files in a script that I run as root (there are other things in
> the script that requires root privileges). So the copy of the file now
> belongs to root, but I want it to belong to the user, so I figured something
> like this:
>
> cp /a/system/file /a/place/in/my/home/directory/
> chown -R <Some user>:<Some Group> /a/place/in/my/home/directory/
>
> Running the env command I noticed my username three times:
> $USER
> $USERNAME
> $LOGNAME
>
> Which one should I use for <Some user> above?
>
> For example:
> chown -R ${USERNAME}:${USERNAME} /a/place/in/my/home/directory/
>
> I didn't find an environment variable for the groups I belong to, so I guess
> I can use the same as for owner, right?
>
> --
> Kind regards
>
> Johnny Rosenberg
>

Tried with a simple script and found that all three of them was "root"
if I ran the script with sudo, so I can't really use any of them. Too
bad…


Regards

Johnny Rosenberg




More information about the ubuntu-users mailing list