On Sat, Jan 24, 2026 at 21:12:48 -0700, [email protected] wrote:
> destination="2026-01-19-03-28-45-00";
> printf "destination=$destination\n";
Never put expansions in the first argument of printf. That argument
is interpreted by printf, with characters like % and \ being special.
What you want is:
printf 'destination=%s\n' "$destination"
> if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
Error 1: "$destination" must be quoted.
Error 2: With no options, grep will treat the first non-option
argument as a Basic Regular Expression, which I don't think is what
you want. Use the -F option to treat it as a plain string.
Error 3: Use the -- option terminator in case the argument begins with
a "-" character.
Also, you may replace "grep >/dev/null" with grep -q.
Finally, the parentheses are not needed.
Thus:
if ! lsblk -alno UUID | grep -qF -- "$destination"; then
printf 'not connected...'
You could also use "case" (sh) or "[[" (bash) to get rid of the grep
altogether. With case, you would need to reverse the order of the
checks, with the positive (connected) case first:
#!/bin/sh
case $(lsblk -alno UUID) in
*"$destination"*) printf 'connected...' ;;
*) printf 'not connected...' ;;
esac
With [[ you may continue checking for the negative first:
#!/bin/bash
if [[ $(lsblk -alno UUID) != *"$destination"* ]]; then
printf "not connected..."
My personal preference would be to check the positive case first,
regardless of which approach you use, because it removes a negation,
making the code easier to read and understand.
> dev="$( blkid --uuid $destination )";
The quotes you've used are optional. The quotes around "$destination"
are required.
dev=$( blkid --uuid "$destination" )
or
dev="$( blkid --uuid "$destination" )"
> printf "dev=$dev\n";
Same as before: use %s in the format argument and "$dev" (quoted!) as
a second argument. That's the only way to print the content *exactly*
as is, with no interpretation.
> 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
Without seeing the output of lsblk -alno UUID we can't help any further.
> Does this line have a syntax error?
> if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
No, just the 3 errors that I listed earlier.