Mustafa
Mustafa

Reputation: 10413

Bash scripting on debian installer not accepting user input on preseeding

I have a very small script that needs to be run on debian installer: (via preseeding, pre installation script)

echo -n -e " # Your option [1] [2] [3]: "
    read REPLY
    if [ "$REPLY" == "1" ] 

The script stops here and whatever I press is just displayed onto screen however it is not accepting the enter key. Normally, when you press 1 and press enter, the read should return 1 to $REPLY. But nothing happens. It keeps accepting user input but no further action happens.

Then, I switched to tty2 with ALT+F2 and run the script there, it was fine, it works as expected, when I press; it takes the input. Why tty1 is not accepting enter as usual?

Upvotes: 5

Views: 1643

Answers (4)

Hansl
Hansl

Reputation: 21

Had the same problem (read not processing my input) with busybox on an embedded Linux.
Took me some time to realize that busybox's read is not CR-tolerant — my terminal program (used miniterm.py) sent CR/LF line ends by default; switching it to LF only solved my problem!

Upvotes: 2

InternetSeriousBusiness
InternetSeriousBusiness

Reputation: 2635

Use debconf for that kind of configuration, it tackles exactly needs like yours.

Adapted example from the manual

Template file (debian/templates):

Template: your_package/select_option
Type: select
Choices: 1, 2, 3
Description: Which option?
 Choose one of the options

Script (debian/config):

#!/bin/sh -e

# Source debconf library.
. /usr/share/debconf/confmodule

db_input medium your_package/select_option || true
db_go

# Check their answer.
db_get your_package/select_option
if [ "$RET" = "1" ]; then
   # Do stuff
fi

Upvotes: 4

eckes
eckes

Reputation: 67047

The following script works fine for me:

#!/bin/sh
echo -n -e " # Your option [1] [2] [3]: "
read

case $REPLY in
    1 ) 
      echo "one" ;;
    2 ) 
      echo "two" ;;
    3 ) 
        echo "three" ;;
    *)
        echo "invalid" ;;
esac

It prints out one nicely if I choose 1. Any reason why you'd like to stick to if...fi?

Upvotes: 0

Nahuel Fouilleul
Nahuel Fouilleul

Reputation: 19305

with bash interpreter, try replace read by :

builtin read

with other sh interpreter, specify the variable name :

read REPLY

Upvotes: 0

Related Questions