How to automatically answer interactive cli program (not script) with bash script?
10,346
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 [...]
Related videos on Youtube
Author by
Mas Bagol
Updated on September 18, 2022Comments
-
Mas Bagol over 1 year
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
. Hereparted -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
toparted
prompt.So, how can I automatically answer that
parted
prompt without using a bash script?-
j0h about 9 yearsThere 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.
-
Eliah Kagan about 9 years
-
-
Mas Bagol about 9 years
never prompts ...
does it means, yes to all? -
A.B. about 9 years@BagolDaplun Never ask in this case means that the default is used.
-
kos about 9 years@BagolDaplun As A.B. said
-s
makesparted
use the default (which isyes
). Also I corrected the command because here you can't combine options since-a
needs an argument.