I'm trying to make a small script to see if you say a specific word, in bash.
Here is my code so far :
if [[ "$NETORDEV" =~ Device ]]; then
echo "You typed Something Device Something"
fi
exit 0
It does not echo what it should, even if i type something along the lines of "random Device stuff"
Please help, i'm at a loss of what to do
Edit : Never mind, i've worked it out, sorry for the inconvienience
vbe
2
What was the issue then?
Shall I flag the thread as solved or will you wait to see (if any) proposals from you peers?
Something like this should work for the above:
if [[ "$NETORDEV" = *Device* ]]; then
echo "You typed Something Device Something"
else
echo "You typed something without Device"
fi
exit 0
Or for a more portable (between various shells) solution try the case statement:
case $NETORDEV in
*Device*)
echo "You typed Something Device Something"
;;
*)
echo "You typed something without Device"
;;
esac
exit 0