Mayuu
Mayuu

Reputation: 39

One Line Command in Linux Bash

I am trying to write a basic one line Linux Bash command, which gives all the numbers between 1 - 1000 as an input to an exe program.

the exe program looks like this:

please insert 1:   1(wanted input)
please insert 2:   2(wanted input)
.
.
.
.
please insert 1000:  1000(wanted input)
success!

so I have tried writing this linux bash command:

for((i=1;i<=1000;i+=1)); do echo "$i"|./the_exe_file; done

but the problem is that my command OPENS the exe file on each iterate of the for... which means, only the first input (1) is right. And, for some reason, the input that is given to the exe file seems not to be good. what can I do? Where is my mistake?

Thanks in advance.

Upvotes: 0

Views: 2558

Answers (4)

dr-who
dr-who

Reputation: 189

In bash:

$ for f in {1..1000}; do echo $f; done 

to test:

$ for f in {1..1000}; do echo $f; done  | uniq | wc -l
1000

Upvotes: 0

pjh
pjh

Reputation: 8064

Try

printf '%s\n' {1..1000} | ./the_exe_file

Upvotes: 1

Paul Hodges
Paul Hodges

Reputation: 15273

Likewise, you might find it more readable to use the tool designed for this.

seq 1 1000 | ./the_exe_file

Upvotes: 1

Poshi
Poshi

Reputation: 5762

You asked the exe to be opened in every loop iteration. It you only need it to be opened a single time, take it out of the loop:

for((i=1;i<=1000;i+=1)); do echo "$i"; done | ./the_exe_file

Upvotes: 1

Related Questions