Because the work needs to validate the data submitted by the user, this is a simple date validation example, you need to know the students can refer to.
The IF statement in the shell needs to make a regular judgment and check the grammatical records.
Datepattern= "^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$"
if [["$STARTDATE" =~ $DATEPATTERN]] && [[$ENDDATE =~ $ Datepattern]]; Then:
else
echo "date format is invalid!"
Exit;
Fi
Regular expressions that are commonly used
if [[$file ' =~ ' start]]
or if [[' $file ' =~ ' start ']]
Example:
#!/usr/bin/ksh
file= "10start11.s"
if [["$file" =~ "Start"]]
then
echo "Success"
else
echo "Failed"
fi
only bash supports [[
Ksh should not support regular in test, use awk grep sed and other tools to implement it
Flag= ' echo $file |awk '/start/'
if ["$flag" = ""];then
Echo "Success"
else
echo "failed"
fi
The Bourne Shell's if statement is the same as most programming languages-the detection condition is true, and if the condition is true, the shell executes the code block specified by the IF statement, and if the condition is false, the shell skips the if code block and continues executing the code.
Syntax for an IF statement:
if[judgment conditions]
then
command1
command2
... Last_command
fi