Skip to main content
added 188 characters in body
Source Link

I'm quite new at bash and I am trying to learn it by creating some small scripts.

I created a small script to look up the DNS entry for multiple domains at the same time. The domains are given as attributes.

COUNTER=0
DOMAINS=()

for domain in "$@"
do
    WOUT_WWW=$(dig "$domain" +short)
    if (( $(grep -c . <<<"$WOUT_WWW") > 1 )); then WOUT_WWW="${WOUT_WWW##*$'\n'}" ; fi

    WITH_WWW=$(dig "www.${domain}" +short)
    if (( $(grep -c . <<<"$WITH_WWW") > 1 )); then WITH_WWW="${WITH_WWW##*$'\n'}" ; fi


    DOMAINS[$COUNTER]="$domain|$WOUT_WWW|$WITH_WWW"
    COUNTER=$(($COUNTER+1))
done

Now I just want to loop through the new "multidimensional" array and give the output like mysql table:

+------------------------------+
| Row 1    | Row 2  | Row 3    |
+------------------------------+
| Value    | Value  | Value    |
+------------------------------+

How can I do that?

I'm quite new at bash and I am trying to learn it by creating some small scripts.

I created a small script to look up the DNS entry for multiple domains at the same time. The domains are given as attributes.

COUNTER=0
DOMAINS=()

for domain in "$@"
do
    WOUT_WWW=$(dig "$domain" +short)
    WITH_WWW=$(dig "www.${domain}" +short)

    DOMAINS[$COUNTER]="$domain|$WOUT_WWW|$WITH_WWW"
    COUNTER=$(($COUNTER+1))
done

Now I just want to loop through the new "multidimensional" array and give the output like mysql table:

+------------------------------+
| Row 1    | Row 2  | Row 3    |
+------------------------------+
| Value    | Value  | Value    |
+------------------------------+

How can I do that?

I'm quite new at bash and I am trying to learn it by creating some small scripts.

I created a small script to look up the DNS entry for multiple domains at the same time. The domains are given as attributes.

COUNTER=0
DOMAINS=()

for domain in "$@"
do
    WOUT_WWW=$(dig "$domain" +short)
    if (( $(grep -c . <<<"$WOUT_WWW") > 1 )); then WOUT_WWW="${WOUT_WWW##*$'\n'}" ; fi

    WITH_WWW=$(dig "www.${domain}" +short)
    if (( $(grep -c . <<<"$WITH_WWW") > 1 )); then WITH_WWW="${WITH_WWW##*$'\n'}" ; fi


    DOMAINS[$COUNTER]="$domain|$WOUT_WWW|$WITH_WWW"
    COUNTER=$(($COUNTER+1))
done

Now I just want to loop through the new "multidimensional" array and give the output like mysql table:

+------------------------------+
| Row 1    | Row 2  | Row 3    |
+------------------------------+
| Value    | Value  | Value    |
+------------------------------+

How can I do that?

Source Link

Bash output array in table

I'm quite new at bash and I am trying to learn it by creating some small scripts.

I created a small script to look up the DNS entry for multiple domains at the same time. The domains are given as attributes.

COUNTER=0
DOMAINS=()

for domain in "$@"
do
    WOUT_WWW=$(dig "$domain" +short)
    WITH_WWW=$(dig "www.${domain}" +short)

    DOMAINS[$COUNTER]="$domain|$WOUT_WWW|$WITH_WWW"
    COUNTER=$(($COUNTER+1))
done

Now I just want to loop through the new "multidimensional" array and give the output like mysql table:

+------------------------------+
| Row 1    | Row 2  | Row 3    |
+------------------------------+
| Value    | Value  | Value    |
+------------------------------+

How can I do that?