[英]Bash redirect and stdin
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. 此命令执行yiic bash脚本,并将参数shell和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. 第一个<<<将参数createmvp传递到终端提示符,当yiic shell src / index.php自行运行时显示。
The second < then allows std in to be returned to the application. 第二个<然后允许将std in返回到应用程序。
However when I run this inside a bash script 但是当我在bash脚本中运行它时
#!/bin/bash
src/protected/yiic shell src/index.php <<< createmvp < /dev/tty
The script doesn't pass createmvp into the shell. 该脚本不会将createmvp传递到外壳中。 If I remove the < /dev/tty bit passing createmvp works, but then recapture the terminal obviously doesn't.
如果我删除通过createmvp的</ dev / tty位,则重新捕获终端显然没有用。 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 艾伦
(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. 我认为
<<< createmvp < /dev/tty
不起作用的原因是, <<<
和<
都是指定标准输入源的方法,您不能两者都做。 <<<
takes a string as an argument and passes it to stdin whereas <
takes a file. <<<
将字符串作为参数,并将其传递给stdin,而<
将文件作为参数。
I think you should use eval: 我认为您应该使用eval:
#!/bin/bash
cmd="src/protected/yiic shell src/index.php <<< createmvp < /dev/tty"
eval $cmd
To exit the script as soon as yiic
processes the exit
command itself, a trap
on exit can be used for the yiic
subshell: 要在
yiic
处理exit
命令本身后立即退出脚本,可以在yiic
子shell上使用exit trap
:
# small addition to cpugeniusmv's answer
(echo createmvp; cat /dev/tty) |
(trap 'kill 0' EXIT; src/protected/yiic shell src/index.php)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.