O
O
oleww052018-12-27 02:47:52
bash
oleww05, 2018-12-27 02:47:52

How to execute a command from a variable?

Why is the variable not converted to a command, but works fine when entered manually?
how to make it read and executed as a command?
It doesn't work like that

#!/bin/bash
z1={0..38}; z2={39..76}; z3={77..114}; z4={115..152}; z5={153..190} #...
for n in $z{1..99}; do
wget http://domain.com/path/$n.jpeg -P /untitled/1/
done

If you write it manually - it works, but it doesn't fit:
#!/bin/bash
for i in {0..38}; do; wget http://domain.com/path/$i.jpeg -P /untitled/1/ ; done
ИЛИ
#!/bin/bash
wget http://domain.com/path/{0..38}.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2018-12-27
@oleww05

z1={0..38}; z2={39..76}; z3={77..114}; z4={115..152}; z5={153..190} #...

What do you think is going to happen here?
In bash, the assignment must be variable=value, no spaces.
And in your case
z1=0 1 2 3 4 5 happens...
in other words,
z1=0 and a lot of unclear things.
Replace it all with
for n in {0..38} {39..76} {77..114} {115..152} {153..190}
do
echo $n
done

True, do not forget that the length of the line is limited, depending on the distribution, it can be 4 kb and 1 kb by default.

C
CityCat4, 2018-12-27
@CityCat4

man eval
UPD: It is possible to enumerate through an arithmetic increment. Dumber, but it will definitely work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question