Reputation: 1322
I'm hoping this is a quick question for a guru. I have the following command which works great from the command line:
src/protected/yiic shell src/index.php <<< createmvp < /dev/tty
This command executes the yiic bash script and passes it the arguments shell and src/index.php.
The first <<< passes the argument createmvp to the terminal prompt which is displayed when yiic shell src/index.php is run on it's own.
The second < then allows std in to be returned to the application.
However when I run this inside a bash script
#!/bin/bash
src/protected/yiic shell src/index.php <<< createmvp < /dev/tty
The script doesn't pass createmvp into the shell. If I remove the < /dev/tty bit passing createmvp works, but then recapture the terminal obviously doesn't. Nothing I seem to do works.
while(!isset($input))
{
$input = trim(fgets(STDIN));
if(!$input)
echo "$configVar can not be NULL";
}
Any ideas, on how to make this work as it does from the command line?
Thanks in advance
Alan
Upvotes: 2
Views: 1137
Reputation: 41
To exit the script as soon as yiic
processes the exit
command itself, a trap
on exit can be used for the yiic
subshell:
# small addition to cpugeniusmv's answer
(echo createmvp; cat /dev/tty) |
(trap 'kill 0' EXIT; src/protected/yiic shell src/index.php)
Upvotes: 1
Reputation: 286
(echo createmvp; cat /dev/tty) | src/protected/yiic shell src/index.php
I think that the reason <<< createmvp < /dev/tty
doesn't work is because both <<<
and <
are ways to specify the source for standard in and you can't do both. <<<
takes a string as an argument and passes it to stdin whereas <
takes a file.
Upvotes: 2
Reputation: 6159
I think you should use eval:
#!/bin/bash
cmd="src/protected/yiic shell src/index.php <<< createmvp < /dev/tty"
eval $cmd
Upvotes: 1