Clean up after shell script that is run via k8s pod on a gpu node for health check
#!/bin/bash



Why not plain /bin/sh?  I don't see any non-POSIX shell constructs in there.


sort | uniq



We could replace with sort -u (that's a standard option).


     echo "Found pending blacklist on ${bad_gpu}"
     exit 1



That message should go to standard error stream: &gt;&amp;2.  The same may be true of the other informational messages.


 for bad_gpu in "{$bad_gpus}"; do



Really?  "{$bad_gpus}" is a single token; I think you meant $bad_gpus there.  Especially as we then expand $bad_gpu unquoted in the next line.


grep Pending| grep Yes &gt; /dev/null 2&gt;&amp;1



If Pending and Yes always occur in the same order, we could simplify to a single command (and we don't need the redirection):

grep -q 'Pending.*Yes'



   if [ $? -eq 0 ]; then



That's an antipattern - it's a sign that you need to move the preceding statement into the if:

if nvidia-smi -i "$bad_gpu" ...
then