We really can't help since we have no idea what $acme2
contains, but I can tell you that your grep
command is looking for lines that start with _acme
. Since the output of dig
is multiple lines and you are echoing the variable unquoted, that will put everything on a single line, so unless the very first string in the output is _acme
, your grep
will match nothing. To illustrate:
$ seq 3 1 2 3 $ acme=$(seq 3) $ echo $acme 1 2 3 $ echo "$acme" 1 2 3 $ echo $acme | grep '^2' $ $ echo "$acme" | grep '^2' 2
So, assuming you have at least one line in your dig
output that begins with _acme
, correctly quoting your variable (which you should ALWAYS do, by the way) should work:
acme3=$(echo "$acme2" | grep "^_acme")
Or, better, especially for arbitrary data like this:
acme3=$(printf '%s\n' "$acme2" | grep "^_acme")
$1
? You should post the debug withset -x
printf '%s\n' "$acme2"
. We really can't help you parse data you don't show us. And clarify exactly what you want to do here. What is the expected output? Why are you expecting a line beginning with_acme
?typeset -p acme2
and b) the expected contents ofacme3
echo $acme2
as-is, you'd have seen it folds all the lines into one, perhaps explaining why thegrep
doesn't stick.