[SOLVED] need help matching string variables in a bash script
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
you can use an online regexp checker to understand how regexp works: http://www.myezapp.com/apps/dev/regexp/show.ws
You will see ^[0-9] will match only a single number, nothing else. To make it properly you need to use double brackets [[ ]] as it was used on the link I posted.
i still haven't a single clue what i did, but it works now !
Code:
MYIP=$(/usr/bin/wget -qO - http://ipecho.net/plain)
if [[ $MYIP =~ ^[0-9].* ]];
then TEXTEN="Connected, IP : $MYIP"
else
TEXTEN="No internet connection"
fi
echo "<p> $TEXTEN </p>"
have you checked it on the link I gave? That is: one digit and after that any number of anything - from the beginning of the line.
a bit better: https://regex101.com/r/sZ9lF4/2
background info: this is part of a web page ( yes , i am using sudoed bash scripts for CGI for system management ) don't try this at home kids ! unless you know what you're doing, which would per se keep you from doing it in the first place.
Obviously i don't know what i'm doing, which is why i am doing it....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.