own : Fix support for multiple files.

This commit is contained in:
Dmitry Voronin 2023-12-10 04:18:37 +03:00
parent 6faa880231
commit e1d78bbe08

View file

@ -2,12 +2,13 @@
# Root user by default. This directory recursively by default.
# Usage: own [USER] [FILES]
function own() {
local file="${2}"
local IFS=$'\n'
local files=("${@:2}")
local user="${1}"
# default to current dir.
if [ "${file}" = "" ]; then
file='.'
if [ "${files[*]}" = "" ]; then
files=(".")
fi
# default to current user.
@ -15,9 +16,11 @@ function own() {
user="${UID}"
fi
for file in "${files[@]}"; do
# set ownership.
chown "${user}":"${user}" -R "${file}" &> /dev/null
# remove access from group and others.
chmod -077 -R "${file}"
done
}