쉘스크립트에서 키보드 입력 어떻게 해야할까요?

whatsup95의 이미지

CentOS 7에서 레드마인을 설치하려고합니다. 레드마인 설치 패키지를 설치하면 여러 옵션들을 사용자가 키보드 입력을 넣게 되어있는데 이걸 쉘스크립트로 구현하고싶습니다.

!/bin/bash

wget https://bitnami.com/redirect/to/818538/bitnami-redmine-4.0.5-6-linux-x64-installer.run

yum -y install wget perl-Data-Dumper

chmod 755 bitnami-redmine-4.0.5-6-linux-x64-installer.run

./bitnami-redmine-4.0.5-6-linux-x64-installer.run

이렇게 실행파일 실행까지는 쉽게 작성할 수 있는데 저 실행파일 안에서 키보드 입력받는것을 잘 모르겠더라구요. 아시는분 부탁드립니다!

muhandozan의 이미지

fgets나 fread, putc, scanf 사용하시면 되옵니당~!! *><*

whatsup95의 이미지

배쉬쉘에서 그런 문법이 있나요?

whatsup95의 이미지

저 실행파일 앞에 echo '1, y, y, n' | 이런식으로 실행파일에 파이프라인으로 넘겨주는식으로 해야할거같은데 잘 모르겠네요 ㅠㅠ

익명 사용자의 이미지

그러니까, 하고 싶은 건 interactive한 프로그램을 사용자 키보드 입력을 가장하여 자동화하고 싶다는 건가요?

그럴 땐 expect 같은 걸 쓰면 됩니다:

https://core.tcl-lang.org/expect/
https://en.wikipedia.org/wiki/Expect

ymir의 이미지

non-interactive 옵션을 제공하는게 있는지 먼저 한 번 확인해 보시고..
해당 프로그램이 stdin 으로 입력을 받는다면 here document 로도 대응할 수는 있습니다.
물론 안 되면, expect 로 가는게 낫구요.

$ cat run.sh
#!/bin/bash
 
read a
echo a = $a
 
read b
echo b = $b
 
read c
echo c = $c
 
exit 0;
 
$ bash run.sh << EOF
> hello
> dear
> world
> EOF
a = hello
b = dear
c = world

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』