1

I have a bash script say test.sh and while executing manually say sh test.sh. First it will ask y/n,then if I give yes,again it will ask y/n and on the second yes, it will ask me to give a server host-name and once I give the host-name again it asks for a series of y/n and finally it will be successfully completed. I am curious to know how to automate like a silent installation.

I tried echo y | sh test.sh... But the issue with this is that for the server host-name also it is giving y

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
gosatriani
  • 307
  • 4
  • 11
  • its not a duplicate.. here the values are dynamic.. please read the qn properly before commenting something – gosatriani Feb 22 '18 at 11:59
  • 1
    @PesaThe I reopened the question, feel free to add the snippet as an answer. gosatrini: I missed the part where you have to give a server name as input – fedorqui Feb 22 '18 at 12:42

1 Answers1

0

You can use something like this:

{ cat <<'EOF'
y
y
Some hostname
EOF
yes; } | ./test.sh

Or use yes / echo instead of the here-document:

{ yes | head -n 2; echo "Some hostname"; yes; } | ./test.sh
PesaThe
  • 7,259
  • 1
  • 19
  • 43