0

I need to make a loop about this script:

#!/bin/bash
exec 3>&1;
result=$(dialog --inputbox "Scan S/N" 10 23 2>&1 1>&3);
result1=$(dialog --inputbox "Scan S/N" 10 23 2>&1 1>&3);
result2=$(dialog --inputbox "Scan S/N" 10 23 2>&1 1>&3);
exec 3>$-;
clear
echo $result;
echo $result1;
echo $result2;

And would be great to have a varible where i can select how many times will the loop run...

I dont have to tell you im pretty newbie in this hehe, thanks in advance. JB

1
  • based on your minimal description of the use-case, you don't need to worry about exec n>&n code. Leave them out, it will just confuse things. Good luck. Commented Sep 22, 2016 at 19:37

2 Answers 2

1

Anytime you talk about a variable number of related variables, you want an array.

n=3
for ((i=0; i<n; i++)); do
    results+=( $(dialog --inputbox "Scan S/N" 10 23 2>&1)) 
done

# individual results can be accessed with ${results[i]} for i=0,1,...,n-1
for res in "${results[@]}"; do
  echo "$res"
done
Sign up to request clarification or add additional context in comments.

Comments

0

The basic way to loop and count is :

c=0
while true; do
  echo "count $c"
  ((c++))
  ((c==100)) && break
done

echo DONE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.