[ command is to evaluate conditional expressions. It's of no use here.
umount doesn't output anything on its standard output (the errors go to stderr),
`sudo umount mount` expands to nothing.
So it's like:
while [ ]
[ command, when not passed any argument beside
] returns false (a non-zero exit status), so you will not enter the loop.
umount had output its errors on stdout, using the
[ command would not have made sense, because the words resulting of that output would never have made up a valid conditional expression.
Here you want:
until sudo umount mount
That is, you want to check the exit status of sudo/umount, not of a
If you wanted to check if
umount output any error or warning on its stderr, that's where the
[ could have been useful. The
-n "some-string" is a conditional expression recognised by the
[ command to test whether
"some-string" is empty or not, so something like:
while [ -n "$(sudo umount mount 2>&1 > /dev/null)" ]; do
But looking for the presence of error or warning messages is generally a bad idea. The
umount command tells us whether or not it succeeds with its exit code, that's much more reliable. It could succeed and still output some warning message. It could fail and not output an error (like when it's killed).
In this particular case, note that
umount might fail because the directory is not mounted, and you would loop forever in that case, so you could try another approach like:
while mountpoint -q mount && ! sudo umount mount; do
Or if "mount" may be mounted several times and you want to unmount them all:
while mountpoint -q mount; do
sudo umount mount || sleep 0.1