If I enter the command
snap list junk
the error message reported is
error: no matching snaps installed
I expect the following to correctly capture any such message in a specified file:
snap list junk 2>&1 >msg_file.txt
That does not work. I’ve tried wrapping the snap command within braces, which I’ve had to do for some cases, but that does not work for this scenario.
Any suggestions?
Test script
#!/bin/sh
tmp="/tmp/$(basename "${0}" ".sh")__$$.tmp" ; rm -f "${tmp}"
#for packageName in junk software-boutique
for packageName in junk
do
skip=0
export packageName
rm -f "${tmp}"
#{ snap list "${packageName}" 2>&1 } >"${tmp}"
#testor=$( snap list "${packageName}" 2>&1 )
snap list "${packageName}" 2>&1 >"${tmp}"
#testor=$( echo "${testor}" | grep 'error: snap' )
#testor=$( grep 'error: snap' "${tmp}" | grep 'not found' )
#testor=$( grep 'error: snap' "${tmp}" )
testor=$( grep 'error: no matching snaps installed' "${tmp}" )
echo "testor = '$testor'"
if [ -n "${testor}" ]
then
echo "\n No SNAP package by name of '${packageName}' ..."
else
if [ -n "${packageName}" ]
then
rm -f "${tmp}"
snap connections "${packageName}" >"${tmp}"
if [ -s "${tmp}" ]
then
echo "\n Found connections related to package '${packageName}':\n"
cat "${tmp}"
echo "\n Skip or Continue ? [S/c] => \c" ; read dowhat
if [ -z "${dowhat}" ] ; then dowhat="A" ; fi
case "${dowhat}" in
[Ss] ) echo "\t Purge of '${packageName}' deferred ...\n" ; skip=1 ;;
* ) echo " Ignoring status of connections ..." ;;
esac
else
echo " Found no connections related to package. Proceeding with purge ...\n"
fi
if [ ${skip} -eq 0 ]
then
echo "to purge"
#snap remove --purge "${packageName}"
echo ""
#snap list "${packagName}"
fi
fi
fi
echo "\n Hit return to continue with next package ..." ; read k
done
My default environment is UbuntuMATE 22.04.5 LTS. The problem was detected and identified there, for both /bin/sh and /bin/bash.
I loaded a test environment for Xubuntu 26.04 LTS. The offending behaviour persists, again for both /bin/sh and /bin/bash.
The issue of the inability by both /bin/bash and /bin/sh being unable to redirect all messages (namely both stdout and stderr to a specified file) is for me a bug. That tells me that SNAP is directing messages to a non-standard “device”, contrary to the spirit of the Linux environment.
I believe that the bug must reside with SNAP because the behaviour exists for both shells.
Can anyone confirm whether they agree that it is a bug?
P.S. I tried to locate an “Issues” tab for the snapd package on GitHub, but that doesn’t exist. ![]()