On Thu, Dec 4, 2025 at 10:17 PM Ionen Wolkens <[email protected]> wrote:
>
> On Fri, Dec 05, 2025 at 10:21:36AM +0800, Zhixu Liu wrote:
> > > -               # If we're still here, setcaps failed.
> > > +               # If we're still here, setcaps failed or filecaps are 
> > > disabled.
> > > +               if [[ -n ${owner} || -n ${group} ]]; then
> > > +                       debug-print "${FUNCNAME}: setting owner on 
> > > '${file}'"
> > > +                       chown "${owner}:${group}" "${file}" || die
> > > +               fi
> >
> > if owner is a number but no group, chown will fail w/ "chown: invalid
>
> Huh, never realized this, kind of assumed it worked given `root:` does.
>
> > spec: '2000:'", how about:
> >
> > local spec=${owner}
> > [[ -n ${group} ]] && spec+=":${group}"
> >
> > chown "${spec}" "${file}" || die
>
> Could keep it as a one-liner using ${var:+}, aka:
>
>     chown "${owner}${group:+:}${group}" "${file}" || die
>
> For those that don't know :+ checks if group is empty and,
> if not, will print what's after it aka :.

Thank you both, I will use Ionen's shorter form.

Reply via email to