In a bash script I want to recursively chown all subfolders of an arbitrary folder with the user and group owners of that given folder.
My approach is something like using stat -c "%U %G" .
But that returns only a pattern of username[whitespace]groupname
Of course I could just try different tools to replace the whitespace with a :
but I would prefer to use a more "built-in" way if there is one, to just apply current ownership to the sub folders.
You don't actually need to parse the output to remove the whitespace - you added that in your command! You can just format it as you like (with
chown
's colon syntax) in the first place:So just pass that to
chown
with command substitution:chown
, likechmod
, can use a reference:So: