0

To explain better; There's a shell script example.sh that upon execution creates a menu:

0. do this
1. do that

I want to create a batch script that calls example.sh then selects one of the options.

I tried the below it just opens the script.

./example.sh; 0
./example.sh; echo 0
2
  • Do you mean you want to call anoter script with parameters or build another script dynamically & lanch it if build is OK ?
    – francois P
    Jan 8, 2020 at 17:17
  • 1
    This will depend on how the script works. Can you share the script here? Even better, can you just share a small part of the script that is enough to reproduce the issue?
    – terdon
    Jan 8, 2020 at 17:18

2 Answers 2

1

Maybe you can dive into "expect" (or some modern derivatives) that are meant to programmatically interact with text based programs.

0

You probably want:

echo 0 | ./example.sh

This will send the string 0\n to the script's standard input.

Your attempts are misguided: with ./example.sh; exit 0 the shell will

  • first run the script,
  • then, after it ends, will run the echo 0 command
2
  • Aw! thank you. If i want to run multiple choices one after another, I assume I could: echo 1 | ./example.sh; echo 0 | ./example.sh Jan 8, 2020 at 17:40
  • 1
    No, you would do printf "%s\n" choice1 choice2 choice3 etc | ./example.sh -- you only want to run the script once, giving it ALL the input. Jan 8, 2020 at 21:12

You must log in to answer this question.

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