0

I'm trying to set up a gulp file which asks for input from the user (for a variable name), but I can't get it working.

I've got gulp-shell echo-ing fine, and it triggers the read command and asks for the input, but the variable isn't saved.

Here's my gulp code:

gulp.task('shell', shell.task([
  'echo hello, whats your name?',
  'read name',
  'echo oh hello, $name'
]));

the output is as follows:

[14:51:47] Starting 'shell'...
hello, whats your name?
Foo
// ^ this is my input
oh hello,
[14:51:49] Finished 'shell' after 1.51 s

As you can see, the name variable, which I set to 'Foo' doesn't get output.

Any ideas?

Craig Wheatley
  • 84
  • 1
  • 10

1 Answers1

2

Reading the input and echo'ing in one line should work. Something like this

gulp.task('shell', shell.task([
  'echo hello, whats your name?',
  'read name;echo oh hello, $name'
]));
Dhiraj
  • 33,140
  • 10
  • 61
  • 78
  • Ha totally worked! thanks! Is this because the gulp-shell is running multiple instances of shell or something per line? – Craig Wheatley May 19 '15 at 14:19
  • 1
    Each line executes in its own context. Unless you store the values in `env` they will not share context. As far as what I understand from the [source code here](https://github.com/sun-zheng-an/gulp-shell/blob/master/index.js#L34) – Dhiraj May 19 '15 at 14:25