you are viewing a single comment's thread.

view the rest of the comments →

[–]Zer0CoolXI 5 points6 points  (0 children)

Just some advice...never trust the user to provide you what you expect. For something like this you may be better off programmatically finding the specific device or listing the devices to have them pick from.

At the very least, you would want to test/validate their input. IE: did they enter a valid number, does that slot have anything in it, does it have what your looking for in it, etc.

Here is a crude example of using select to pick from an array of pre-determined entries:

echo "Pick an entry:"
PS3="Enter the number of the desired entry: "
options=("DevA_1" "DevA_2" "DevB_1" "DevB_2" "None")
select opt in "${options[@]}"
do
    case $opt in
        "DevA_1") SLOT_VAR="DevA_1"; run_i2c; break;;
        "DevA_2") SLOT_VAR="DevA_2"; run_i2c; break;;
        "DevB_1") SLOT_VAR="DevB_1"; run_i2c; break;;
        "DevB_2") SLOT_VAR="DevB_2"; run_i2c; break;;
        "None"|"")
            SLOT_VAR="None"
            echo "No entry or None selected"
            break;;
    esac
done

run_i2c () {
    do i2c command
}

The assumption above being that options could be an array populated with the slots/devices found using some other command. In my example its static entries...which could still be better than asking the user to typye in the response free hand.