-1

I have a setup.sh shell script which needs to be run on Ubuntu to setup something.

I have made another shell script (say sample.sh) which installs pre-requisites before running 'setup.sh' and then finally it triggers 'setup.sh'

setup.sh script for example contains the below sample prompts which require user inputs

  1. Press Enter to use default:

How to provide Enter key press as input instead of manually entering.

KBNanda
  • 595
  • 1
  • 8
  • 25
  • you can use tools like [tag:expect] (for Tcl) and [tag:pexpect] (for Python). try my [sexpect](https://github.com/clarkwang/sexpect/) if you prefer shell. – sexpect - Expect for Shells Sep 07 '22 at 02:00
  • The below answer did not have a solution for this question! https://stackoverflow.com/questions/14392525/passing-arguments-to-an-interactive-program-non-interactively – KBNanda Sep 07 '22 at 04:48

1 Answers1

-1

If the prompts are simple then you can pass the desired inputs on stdin. A heredoc-based example might look like:

#!/bin/bash
# blank line for "Press Enter"
# "y" for response to y/n question
# "string-1 value" for the response to that prompt
./setup.sh <<EOF

y
string-1 value
EOF

If the prompts are more complex, like if there's branching logic based on user inputs, then you may need a more powerful tool like expect.

tjm3772
  • 2,346
  • 2
  • 10
  • Not my downvote, but please refrain from answering common FAQs; instead, vote to close as a duplicate. The [`bash` tag info page](/tags/bash/info) has a collection of frequently asked questions with answers. – tripleee Sep 07 '22 at 04:38