if [ $ans == "yes" ]; then echo "OK, let's get going" else exit fi
There are, however, pretty just some assessments which you may run – whether or not or not strings are the an identical or not and even how they relate alphabetically. The script below compares two strings in some methods.
#!/bin/bash echo -n "Enter first string: " be taught str1 echo -n "Enter second string: " be taught str2 echo # run assessments to see how strings relate if [ "$str1" = "$str2" ]; then echo strings are the an identical; fi if [ "$str1" == "$str2" ]; then echo strings are the an identical; fi if [ "$str1" != "$str2" ]; then echo "$str1" and "$str2" differ; fi if [ "$str1" < "$str2" ]; then echo "$str1" comes first alphabetically; fi if [ "$str1" > "$str2" ]; then echo "$str2" comes first alphabetically; fi if [ -z "$str1" ]; then echo string1 is null; fi if [ -z "$str2" ]; then echo string2 is null; fi if [ -n "$str1" ]; then echo string1 is not null; fi if [ -n "$str2" ]; then echo string2 is not null; fi
In a number of of the assessments above, characters are inserted sooner than quotes to make it possible for the strings are displayed inside quote marks.
Here’s a script that makes use of this check out.
#!/bin/bash echo -n "enter a 12 months> " be taught 12 months this_year=`date +%Y` # get current 12 months using the date command if [ "$year" -lt $this_year ]; then diff=`expr $this_year - $12 months` echo "Wow, that was $diff 12 months{s} up to now" elif [ "$year" -gt $this_year ]; then diff=`expr $12 months - $this_year` echo "Solely $diff 12 months(s) to go" else echo "$12 months is current 12 months" fi
Uncover that the script above makes use of if, else if and else logic in its place of a lot of neutral if assessments.
You might as effectively try to amass mis-entered info with directions like these which will loop until an accurate 12 months is entered.
#!/bin/bash echo -n "Enter 12 months> " be taught 12 months re="^[0-9]+$" whereas ! [[ $year =~ $re ]] do echo "error: Yr need to be numeric" echo -n "12 months> " be taught 12 months achieved
The examples above are fairly superior. They organize a numeric expression which will match any string of digits. If it doesn’t match (the “!” throughout the script means “not”), an error will doubtless be displayed and the script will proceed looping until it does.
Thanks for being a valued member of the Nirantara household! We admire your continued help and belief in our apps.
If you have not already, we encourage you to obtain and expertise these improbable apps. Keep linked, knowledgeable, trendy, and discover superb journey presents with the Nirantara household!
Thank you for being a valued member of the Nirantara family! We appreciate your continued support and trust in our apps.
- Nirantara Social - Stay connected with friends and loved ones. Download now: Nirantara Social
- Nirantara News - Get the latest news and updates on the go. Install the Nirantara News app: Nirantara News
- Nirantara Fashion - Discover the latest fashion trends and styles. Get the Nirantara Fashion app: Nirantara Fashion
- Nirantara TechBuzz - Stay up-to-date with the latest technology trends and news. Install the Nirantara TechBuzz app: Nirantara Fashion
- InfiniteTravelDeals24 - Find incredible travel deals and discounts. Install the InfiniteTravelDeals24 app: InfiniteTravelDeals24
If you haven't already, we encourage you to download and experience these fantastic apps. Stay connected, informed, stylish, and explore amazing travel offers with the Nirantara family!
Source link