Answer the question
In order to leave comments, you need to log in
How to loop with two variables?
I use a loop within a loop
#!/bin/bash
for a in {1..3}; do
for b in {4..6}; do
echo "text untitled/$a.rar /untitled/$b.rar"
done; done
Получается так:
text untitled/1.rar /untitled/4.rar
text untitled/1.rar /untitled/5.rar
text untitled/1.rar /untitled/6.rar
text untitled/2.rar /untitled/4.rar
text untitled/2.rar /untitled/5.rar
text untitled/2.rar /untitled/6.rar
text untitled/3.rar /untitled/4.rar
text untitled/3.rar /untitled/5.rar
text untitled/3.rar /untitled/6.rar
text /untitled/1.rar /untitled/4.rar
text /untitled/2.rar /untitled/5.rar
text /untitled/3.rar /untitled/6.rar
Answer the question
In order to leave comments, you need to log in
#!/bin/bash
for (( a=1, b=4; a <= 3; a++, b++ ))
do
echo "text untitled/$a.rar /untitled/$b.rar"
done
You can achieve the result with the usual for loop:
for a in "1 3" "2 4" "5 6" ; do set -- $a ; echo "text untitled/$1.rar /untitled/$2.rar" ; done
Essence:
We break the $a variable into arguments.
Next, we print not the variable $a itself, but the arguments $1 and $2.
Result:
text untitled/1.rar /untitled/3.rar
text untitled/2.rar /untitled/4.rar
text untitled/5.rar /untitled/6.rar
Source: https://www.opennet.ru/ docs/RUS/bash_scripting_gui...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question