Mike Thrussell
Mike Thrussell

Reputation: 4515

keyboard input on bash scripts executed within 2nd bash script

I'm trying to download a file and run it using the following script:

wget https://github.com/glenpike/npm-g_nosudo/archive/master.zip
unzip master.zip
cd npm-g_nosudo-master
./npm-g-no-sudo.sh
cd ../
rm -rf npm-g_nosudo-master
rm master.zip

The downloaded script pauses twice requiring user input:

  1. an 'enter' key press
  2. an 'y' followed by an 'enter'

How can I include this input in the above script?

Upvotes: 0

Views: 69

Answers (2)

StackBox
StackBox

Reputation: 326

In the bash script: https://github.com/glenpike/npm-g_nosudo/blob/master/npm-g-no-sudo.sh ,you can find

read -p "Do you wish to update your .bashrc/.zshrc file(s) with the paths and manpaths? [yn] " yn

on line 142, which means that you need to type something when you run this bash script.

So, one way to solve your problem is to fork this repo and modify it.

Upvotes: 1

Josh Jolly
Josh Jolly

Reputation: 11786

If the downloaded script is just reading from stdin, you can simply echo or printf the inputs:

echo -e "\ny\n" | ./npm-g-no-sudo.sh

Or:

printf "\ny\n" | ./npm-g-no-sudo.sh

Upvotes: 1

Related Questions