Getting started with conditionals

  • + 0 comments

    Easy solution:

    #!/bin/bash
    
    read CHAR
    
    [ ${#CHAR} -eq 1 ] && [ $CHAR == 'Y' ] || [ $CHAR == 'y' ] && echo "YES" && exit 0
    [ ${#CHAR} -eq 1 ] && [ $CHAR == 'N' ] || [ $CHAR == 'n' ] && echo "NO" && exit 0
    

    EXPLANATION : : we are reading the char, :next if the char == length 1 we pass that to check if it is y,Y,n,N if it is anyone of it we print and exit