How to automate the manual input for command in bash script

227 Views Asked by At

I have command called serverspec-init which prompts

Select OS type:

  1) UN*X
  2) Windows

Select number:

Now I have manually enter value 1 or 2. But I want to automate this so when i run script it automatically pick the value from variable and give input here.

2

There are 2 best solutions below

0
John C On

I can't get my WSL installation working, for some reason, but I believe that you're looking for the $OSTYPE environment variable. On my Ubuntu machine, the value is linux-gnu and a MINGW shell gives msys.

Note that you'll need to make sure that your script is explicitly running BASH.

0
Jack On

You need the expect module:

- name: Select OS
  expect:
    command: /path/to/serverspec-init
    responses:
      Select number: "{{ OS_type_num }}"