Multiple variables into one variable with wildcard

blox

I have this script:

#!/bin/bash
ping_1=$(ping -c 1 www.test.com  | tail -1| awk '{print $4}' | cut -d '/' -f 2 | sed 's/\.[^.]*$//')
ping_2=$(ping -c 1 www.test1.com | tail -1| awk '{print $4}' | cut -d '/' -f 2 | sed 's/\.[^.]*$//')
ping_3=$(ping -c 1 www.test2.com | tail -1| awk '{print $4}' | cut -d '/' -f 2 | sed 's/\.[^.]*$//')
ping_4=$(ping -c 1 www.test3.com | tail -1| awk '{print $4}' | cut -d '/' -f 2 | sed 's/\.[^.]*$//' )

Then I would like to treat the outputs of ping_1-4 in one variable. Something like this:

#!/bin/bash

if [ "$ping_*" -gt 50 ]; then
    echo "One ping is to high"
else
    echo "The pings are fine"
fi

Is there a possibility in bash to read these variables with some sort of wildcard?

$ping_*

Did nothing for me.

janos

I don't think there's such wildcard. But you could use a loop to iterate over values, for example:

exists_too_high() {
    for value; do
        if [ "$value" -gt 50 ]; then
            return 0
        fi
    done
    return 1
}

if exists_too_high "$ping_1" "$ping_2" "$ping_3" "$ping_4"; then
    echo "One ping is to high"
else
    echo "The pings are fine"
fi

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

scanf multiple variables or one variable

"Describe (Pandas)" multiple variables as one variable

Put Multiple Variables in one Variable? c++

Split one variable into multiple variables in R

Nginx map regex with multiple variables to one variable

Recoding multiple variables based on condition of one variable

batch file programming multiple variables into one variable

combine multiple variables in cell to one variable

Gathering multiple dummy variables as one categorical variable in R

Plotting multiple X variables for one continuous Y variable in a single plot

How to visualize multiple categorical variables vs one continuous variable in R

convert one variable into two variables by multiple conditions in R

react one state variable depends on multiple other states variables

How could one branch multiple variables under another variable in R?

How to integrate with respect to one variable while having multiple variables

Split data clumped in one variable to multiple variables in R

Create one new variable that is a logical based on multiple variables

how do I split from one variable into multiple variables in javascript?

Can we replace one variable with multiple variables using sed

Two variable variables in one variable

Multiple variables in one array?

Correlations of a variable with multiple variables

Split variable into multiple variables

One variable instead of multiple

Multiple strings in one variable

Consolidate different variables to one variable

Storing different variables in one variable

Perform wildcard searches with multiple columns in one parameter using dynamic SQL

Select multiple rows with same wildcard one time foreach