* [email protected] <[email protected]> [26-01/24=Sat 21:12 -0700]:
> # blkid --uuid 2026-01-19-03-28-45-00
> /dev/sdc
> Meaning that the block device with that UUID is connected to the system.
> 
> When this executes,
> 
>     destination="2026-01-19-03-28-45-00";
>     printf "destination=$destination\n";
>     if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
>       printf "destination device not connected.  Aborting.\n"
>     else
>       printf "destination device is connected.\n"
>       dev="$( blkid --uuid $destination )";
>       printf "dev=$dev\n";
>       # FTH;
>     fi;
>     
> this is the output.
> destination=2026-01-19-03-28-45-00
> destination device not connected.  Aborting.
> 
> With the device being present, I expect this.
> destination=2026-01-19-03-28-45-00
> destination device is connected.
> dev=/dev/sdc
> 
> Does this line have a syntax error?
>     if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then

The syntax is correct but the logic is confusing.  Try this:

$ PS1='$?\$ '
0$ blkid --uuid 473f5ac6-f392-488c-b51f-1798531db64a
/dev/vda2
0$ blkid --uuid 473f5ac6-f392-488c-b51f-1798531db64aXXXX
2$ isConnectedUUID(){ lsblk -alno UUID|grep "$1" >/dev/null;}
0$ isConnectedUUID 473f5ac6-f392-488c-b51f-1798531db64a
0$ isConnectedUUID 473f5ac6-f392-488c-b51f-1798531db64aXXXX
1$ if isConnectedUUID 473f5ac6-f392-488c-b51f-1798531db64a;then echo OK;else 
echo OOPS;fi
OK
0$

Reply via email to