7

I've googled this, and almost all I could find is to answer a bash script and this doesn't work for me. The answers I found told to do:

echo "yes" | ./script

or

./script <<< yes

or something like that. It didn't work for me. My guess is that's because what I want to do is to auto answer an executable program, not a script. More specifically, I want to auto answer parted. Here

parted -a optimal /dev/sda mklabel msdos
Warning: The existing disk label on /dev/sda will be destroyed and
all data on this disk will be lost. Do you want to continue?
Yes/No? _

I try to do

echo "yes" | parted -a optimal /dev/sda mklabel msdos

and

parted -a optimal /dev/sda mklabel msdos <<< yes

Both methods didn't work. Those didn't answer yes to parted prompt.

So, how can I automatically answer that parted prompt without using a bash script?

muru
  • 193,181
  • 53
  • 473
  • 722
Mas Bagol
  • 1,311
  • 4
  • 21
  • 34
  • 2
    There is a language for specifically that purpose, to automate interactive programs. it is called "expect" and you can call it from within a bash script. – j0h Apr 25 '15 at 10:39
  • Related: [parted script to automate disk partitioning](https://forums.gentoo.org/viewtopic-t-886802-view-next.html?sid=6851c96d655f7b5d4b7c6d7ae29f3912) – Eliah Kagan Apr 25 '15 at 17:18

1 Answers1

10

With parted, you can just add the -s option:

parted -a optimal -s /dev/sda mklabel msdos

From the Trusty man page for parted:

[...]
       -s, --script
              never prompts for user intervention
[...]
kos
  • 35,535
  • 13
  • 101
  • 151
  • `never prompts ...` does it means, yes to all? – Mas Bagol Apr 25 '15 at 11:40
  • 3
    @BagolDaplun Never ask in this case means that the default is used. – A.B. Apr 25 '15 at 12:09
  • @BagolDaplun As A.B. said `-s` makes `parted` use the default (which is `yes`). Also I corrected the command because here you can't combine options since `-a` needs an argument. – kos Apr 25 '15 at 17:09