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


  become: yes

I'd like to use backspace because the script i'm using is answering in advance so that I just have to press enter if i'm ok but for one question i'd like to change the given answer. But so far i didn't find a way to use backspace. Anyone would know ?

0

1 Answer 1

3

The ASCII control for backspace is '\b'. This works with double quotes:

- name : Execute the script and answer to question in term
  expect:
  command: "echo Q"
  echo: "yes"
  responses:
   Q: "b\bc"

for example returns prints to stdout 1^Hc, where ^H is indeed the backspace control.

This may only move the cursor backwards though, not erase the previous character. Just for example, in my bash shell:

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

produces a as output, but

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

produces c, since the cursor was moved back, than the a was overwritten.

1
  • Thanks ! I'll see if it's working that way in the ansible module, i'm afraid it will only wrotte the letter 'b' as '\' will be interpreted as an escape char ? Tell you more in a few minutes !
    – Ayra
    Sep 25, 2018 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.