0

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.

4 Answers 4

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

If it worked and solved your problem, it would be good that you mark the answer as accepted :-)
1

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

seq 1 1000 | ./the_exe_file

2 Comments

Strictly speaking, seq may not be installed on the current machine, while bash is guaranteed to be available on a machine running a bash script.
True. If it's there, I'd use it. If not, I'd use a loop rather than bothering to install it. :)
1

Try

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

Comments

0

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

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.