I am trying to write an if statement in shell combined with command last The if statement should check the output of command last and print only the lines of which month user chose. For example user input is: Mar January
Result should be: "Mar Good format" and print all the lines of the command last that have Mar as their month.
For January it should say: "January Bad format" and print nothing else.
This is the code so far:
echo "Enter the month name (acording to last command results format):"
read month month1
if [[ $month == [aA-zZ][aA-zZ][aA-zZ] ]]
then
echo "$month Good format"
else
echo "$month Bad format"
fi
It only checks for one of the inputs and prints only for one input. I don't know how to check both of the strings in one if statement and print the results for both, if one fails and the other is correct.
checkMonthfunction that accepts a single month. Then call that function for bothmonthandmonth1. If your code will never ever read anything other than two words, then that's the end of it. If you code has to read an indeterminate number of words, then you'll probably want to read a string and parse it into a list of words and then iterate over the list.