[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Solved] Re: Difficulty with a shell function.



On Sun, Jan 25, 2026 at 11:54:37 -0700, peter@easthope.ca wrote:
> The drive isn't formatted

What?

> and has a UUID such as 
> 2026-01-19-03-28-45-00. Shorter than a UUID for a file system.

This looks like a timestamp.

> OK in a simple test.  Suggestions always welcome.  Something may be 
> more efficient  than the long pipeline.
> lsblk --nodeps -o name,serial | grep -F -- "$destination" | cut -d ' ' -f1 

It would help if we knew what the output looks like.  On my system:

hobbit:~$ sudo lsblk --nodeps -o name,serial
[sudo] password for greg: 
NAME    SERIAL
nvme0n1 UPJQD01ZTJ03L4

So... you *have* the serial number (somehow) and you *want* the "name"
field?  The obvious way would be to use awk:

    lsblk --nodeps -o name,serial |
        awk -v serial="$serial" '$2 == serial {print $1}'

On my system:

hobbit:~$ serial=UPJQD01ZTJ03L4
hobbit:~$ sudo lsblk --nodeps -o name,serial | awk -v serial="$serial" '$2 == serial {print $1}'
nvme0n1

awk -v isn't 100% safe with all inputs, but if your serial number is
reasonable (alphanumeric, maybe with some basic punctuation, but no
backslashes or control characters) it should be OK.


Reply to: