-1

I want to use multiple variable in for loop at once in sh.

I have a query like this:

top -n 1 -b -c| awk -vOFS="\t" '{print $1,$2,$9}'

I know i use for loop in bash like this:

for i in {2..10}
do
    echo "output: $i"
done

what i want to try is:

for x y z in $(top -n 1 -b -c| awk -vOFS="\t" {print $1,$2,$9}')
do
    echo "output: $x $y $z"
done
2

1 Answer 1

2

Pipe to a while read loop:

top -n 1 -b -c| awk -vOFS="\t" '{print $1,$2,$9}' | while IFS=$'\t' read -r x y z
do
    echo "output: $x $y $z"
done
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.