0

I've looked around and haven't found an answer to this. This is not to be mistaken with questions about bash scripts.

I'm looking to automate an installation for a composer package. There are several requested inputs during the installation process - though they have acceptable defaults. I would like to output a through multiple times to accept the defaults with a bash function.

sage() {
  if (( $# == 0 ))
  then
    composer create-project roots/sage $1
  else
    composer create-project roots/sage
  fi

  echo "\r";
  echo "\r";
  echo "\r";
  echo "\r";
  echo "\r";
  echo "\r";
  echo "https://localhost/$1";
}

This doesn't do what I want, and still focuses inside the first input box. How do I need to change this so the carriage return is inserted after the package has installed?

Trying Expect:

  • Does it have to be verbatim what the input question is or is it just a regex?

Edit:

So far, I've tried

expect "Theme Name [Sage Starter Theme]" { send "\r" }
------------------------------------------------
expect "Theme Name [Sage Starter Theme]" 
send "\r"
Dan
  • 919
  • 1
  • 10
  • 28
  • 4
    "expect" is what you want to use. – Red Cricket Sep 26 '18 at 17:17
  • If I understand, you want the things you echo to be passed as input to the composer command? – Gem Taylor Sep 26 '18 at 20:15
  • Then perhaps you need to look at the bash `<<<` pipe operator. – Gem Taylor Sep 26 '18 at 20:22
  • `<<<` is a less-capable, less portable, shorthand version of heredoc support. If you're going to learn only one thing, should probably make it the more capable thing. – Charles Duffy Sep 26 '18 at 20:57
  • @DanielFoust, if the more generalized questions about scripts' answers work just as well with functions, your question is still duplicative of them; there's no point to a narrower question unless the other ones didn't get answers that successfully apply. Take all the `echo`s out of your function, and feed that input on a heredoc: `sage < – Charles Duffy Sep 26 '18 at 20:59
  • 2
    ...that said, a *well-written* installer (and there are many of those -- you should check whether `composer` is one, and push a patch upstream if not) will provide a better way to override inputs -- a separate named environment variables per potential prompt, a config file, etc; assuming that the same questions will be asked in the same order between releases makes for needlessly fragile code. – Charles Duffy Sep 26 '18 at 21:03

0 Answers0