Vi Ki Vi Ki - 3 months ago 13
Bash Question

How to use several commands through the pipe as shell script

I am using firebase.

I want to write a shell script that do the following:
Executing two commands:


  1. firebase init

  2. firebase deploy



The problem is that
firebase init
prompts with several questions.
The first one I want to answer with y for yes and enter afterwards.
Then press the key space to deselect one item and enter to continue.
A few other questions follow.

But I cannot make
firebase init
to accept the first entries I mentioned above.

When I use "echo y | firebase init" it works. But when I add the space key and enter
firebase init
exits without doing what it should.

Is it possible to solve this problem. I am new to shell scripting. I am using Cygwin with Windows 7.

Answer

From the docs the firebase init command just creates the file firebase.json. Why not do it interactively then just manually generate the JSON later?

Ie if you do it and it generates

{
  "firebase": "myfirebase",
  "public": "app",
  "ignore": [
    "firebase.json",
    "**/.*",
    "**/node_modules/**"
  ]
}

then you can just do

$ echo $'{\n  "firebase": "myfirebase",\n  "public": "app",\n  "ignore": [\n    "firebase.json",\n    "**/.*",\n    "**/node_modules/**"\n  ]\n}\n' >firebase.json
$ firebase deploy
Comments