向Ansible expect(或shell)模块发送退格(以回答术语中的scrpit)

向Ansible expect(或shell)模块发送退格(以回答术语中的scrpit),shell,ansible,Shell,Ansible,我想使用backspace,因为我使用的脚本是预先回答的,所以如果我可以,我只需按enter键,但对于一个问题,我想更改给定的答案。但到目前为止,我还没有找到使用退格的方法。有人会知道吗?退格的ASCII控件是'\b'。这适用于双引号: - name : Execute the script and answer to question in term expect: command: ./"{{ script_name }}" responses: Questi

我想使用backspace,因为我使用的脚本是预先回答的,所以如果我可以,我只需按enter键,但对于一个问题,我想更改给定的答案。但到目前为止,我还没有找到使用退格的方法。有人会知道吗?

退格的ASCII控件是
'\b'
。这适用于双引号:

- name : Execute the script and answer to question in term
  expect:
    command: ./"{{ script_name }}"
    responses:
      Question:
        - ''
        - ''
        - ''
        - 'backspace' #?


  become: yes
例如,将打印返回到标准输出
1^Hc
,其中
^H
实际上是退格控件

但这可能只会将光标向后移动,而不会擦除上一个字符。例如,在我的bash shell中:

- name : Execute the script and answer to question in term
  expect:
  command: "echo Q"
  echo: "yes"
  responses:
   Q: "b\bc"
产生
a
作为输出,但

/bin/bash -c "echo a$'\b'"

产生
c
,因为光标向后移动,所以
a
被覆盖

谢谢!我来看看它在ansible模块中是否是这样工作的,恐怕它只会写出字母“b”,因为“\”会被解释为转义字符?几分钟后告诉你更多!
/bin/bash -c "echo a$'\b'c"