On Fri, Apr 25, 2025 at 10:50 AM Greg Wooledge wrote:
>
> Just a few notes:

thanks for the feedback!

> On Fri, Apr 25, 2025 at 10:39:58 -0400, Lee wrote:
> > #!/bin/bash
> > # see if there are any Debian updates and pop-up a notice if there are
> >
> > # needs an /etc/sudoers.d/adm-apt-privs that has
> > #   Cmnd_Alias    ADM_COMMANDS = /usr/bin/apt update
> > #   %adm          ALL = (root) NOPASSWD: ADM_COMMANDS
> >
> > # get a temporary file
> > tempf=$(mktemp -q --tmpdir=/tmp -t updXXXXX)
> > stat=$?
> > if [ ${stat} != 0 ]; then
> >    echo "OhNoes!!! Unable to create a temporary file.  Status: ${stat}"
> >    exit 9
> > fi
>
> You're not actually using the exit code, other than to check for
> success vs. failure, so you could do this instead:
>
> if ! tempf=$(mktemp -q --tmpdir=/tmp -t updXXXXX); then
>     echo "OhNoes!!! ..." >&2
>     exit 9
> fi

I'm still at the stage where I like keeping things simple and easy to
debug - even if it is more lines in the script.

>     echo "OhNoes!!! ..." >&2

hrmm... yes, I probably should put the error message to stderr

> > size=$(ls -s $tempf | awk '{print $1}')
> >
> > [ $size != "0" ] && \
> > notify-send  -u critical  "Debian updates available" "$(cat $tempf)"
>
> Again, you're not actually using the size, other than to check whether
> the file is empty.  The shell has a builtin test operator for empty
> vs. non-empty files: -s.

Right.  I missed that.  Thanks for pointing that out.

> Also, you should quote "$tempf".
>
> [ -s "$tempf" ] && notify-send ...

is there any way that
  $(mktemp -q --tmpdir=/tmp -t updXXXXX)
would return a 0 status and a filename with embedded spaces .. or with
anything that would require quoting?

Yes, on general principles, quoting filenames is the Right Thing but
is there any way it could make a difference here?

Thanks,
Lee

Reply via email to