使用 "ask dialog" 命令立即通过 Bash 命令传递文本

using "ask dialog" command to immediately pass text through Bash command

我想使用“提问对话框”命令立即传递问题。我正在尝试使启动终端和 运行“询问对话框”的过程自动化。每当我的 bash 脚本运行时,它会在 Alexa 实例打开后暂停。

#!/bin/bash/
cd /Users/AlexaDirectory/
ask dialog 
#this is where I need to ask Alexa a question automatically. 
#I have tried running "ask dialog && (insert question)", but the script pauses once it reaches "ask dialog"
echo "end"

这是我通常在 运行 .sh

时看到的内容
MacBook-Pro Desktop % bash Test.command
Defaulting locale to the first value from the skill manifest: en-US

======================================= Welcome to ASK Dialog =======================================
=========== In interactive mode, type your utterance text onto the console and hit enter ============
===================== Alexa will then evaluate your input and give a response! ======================
=== Use ".record <fileName>" or ".record <fileName> --append-quit" to save list of utterances to a file. ===
=============== You can exit the interactive mode by entering ".quit" or "ctrl + c". ================

User  > 

如果无法立即传递问题,是否可以将击键发送到终端?

在 Charles Duffy 的帮助下,使用 herestring 就是答案。

调用 ask dialog 时进程冻结,修复程序正在发送 ask dialog <<< "question for alexa placed here"。这也会立即结束 Alexa 实例。

您可以尝试使用 the expect command。我一直在努力解决类似的问题。 运行 ask init 在非交互模式下。最后我是这样解决的

echo '#!/usr/bin/expect 
spawn ask init 
expect "? Skill Id (leave empty to create one):" 
send "my-skill\r" 
expect "? Skill package path:" 
send "./path/to/skill-package\r" 
expect "? Lambda code path for default region (leave empty to not deploy Lambda):" 
send "./path/to/lampda-package\r"
' > ask_init.sh
chmod u+x ask_init.sh 
./ask_init.sh

仅供参考,我也尝试过使用 |echo 的组合来传递答案,如下所示:

echo 'quantum-skill
./path/to/skill-package
./path/to/lampda-package
' | ask init

printf,像这样:

printf 'quantum-skill\n./path/to/skill-package\n./path/to/lambda-package\n' | ask init

后者均无效。所以我建议改用 expect