Solved, I'm blind as a bat...
A small script that shall echo "Stopping" if user presses "n" or "N", else echo "Starting".
I can't figure out how to get the syntax right?
Code:
#!/bin/bash
while [[ "$SVAR" != "n" && "$SVAR" != "N" && "$SVAR" != "j" && "$SVAR" != "J" ]]
do
echo "Start or stop?"
read -n 1 SVAR
echo ""
echo "Typed letter is $SVAR"
if [ "$SVAR" == "N" ] || [ "$SVAR2" == "n" ] ; then
echo "Stopping"
else
echo "Starting"
fi
done
Typing "N" echoes "Stopping", correct. However, typing "n" echoes "Starting"!
I have tried several variants of that if statement:
Code:
if [ "$SVAR" == "N" || "$SVAR2" == "n" ] ; then
if [[ "$SVAR" == "N" || "$SVAR2" == "n" ]] ; then
if [ "$SVAR" == "N" -o "$SVAR2" == "n" ] ; then
if [[ ("$SVAR" == "N") || ("$SVAR2" == "n") ]] ; then
The variable $SVAR is assigned correct letter, so it has to be the if statement that's not correct.
The reply when pressing "n" is always
Code:
# /usr/local/sbin/test
Start or stop?
n
Typed letter is n
Starting