S
S
SOTVM2019-01-12 16:39:21
bash
SOTVM, 2019-01-12 16:39:21

How to insert a variable into grep?

how to substitute the mask
variable in the test=$( echo $ip | grep -o '^ 192.168. ' )
#!/bin/bash
ip="192.168.33.44"
mask="192.168."
test=$(echo $ip | grep -o '^ 192.168. ')
if [ "$test" != "" ];
then echo OK $ip;
else echo BAD
fi;
PS
the meaning of the script
is to check the IP by mask
give yes / no

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
q2zoff, 2019-01-12
@sotvm

Like this:

...
test=$(echo $ip | grep -o "^$mask")
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question