F
F
fokin_nikolay19892016-09-27 16:26:50
bash
fokin_nikolay1989, 2016-09-27 16:26:50

How to add comparison in bash?

What is the principle, if the UUID of the inserted flash drive is equal to the specified UUID value, (or, for example, the list of UUIDs is written to a file), then the UUID output matches

#!/bin/bash
echo "NACHALO"
UUID=$(blkid -s UUID -o value -t  TYPE=vfat)
echo "VIVOD UUID"

echo " $UUID"
if [0E48-D3D6 == "$UUID"]; then
echo "good"
else
echo "ne good"
fi

here is an example of what I wrote, but even if it falls on an error

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
abcd0x00, 2016-09-28
@fokin_nikolay1989

You need to understand that this is a program call, and not just a construction.
If you decompose it into components, you get

[ - программа
0E48-D3D6 - первый аргумент
== - второй аргумент
"$UUID" - третий аргумент
] - четвёртый аргумент

It turns out
[ "0E48-D3D6" "==" "$UUID" "]"

S
Smithson, 2016-09-27
@Smithson

You need to match strings, bash has a separate syntax for that.
if [ "$a" -ne "$b" ]

R
romy4, 2016-09-27
@romy4

Comparison is almost correct
ALWAYS conditions and operators are framed
if on the right in quotes, then on the left in quotes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question