I am trying to implement a check for different possibilities of Yes/No. Below code is working fine but is there any simple way for doing this.
Note: I am using bash version 2.02.0.
read -p "Using dest path :${DESTPATH}" flag;
OPT=$(echo $flag|awk '{print tolower($0)}')
if [[ ${OPT:0:1} != 'y' ]]; then
echo "Exiting..."; return
fi
You don't need to call awk
at all. You can take advantage of globbing:
read -p "Using dest path :${DESTPATH}" flag
if [[ $flag != [yY]* ]]; then
echo "Exiting...";
exit 1
fi
[yY]*
will match any string starting with either y
or Y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With