0

How can I write a .sh file to automate input? For example I have a simple program that asks for a name and a few other things. I have so far

#!/bin/bash

echo alice
echo 5

I try to use it like

./program < ./file.sh

but it seems to take #!/bin/bash as input. I am wanting the first input the program takes to be alice and then directly after 5 which should terminate the program.

1 Answer 1

1
  • command < file will redirect content of file to command

to redirect output from executable (in your case execution of file.sh ) use

./file.sh | ./program

note that | is called pipe

see man bash §redirection

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .