Bash script not working with `sh`

I was testing a simple script and I was wondering why it works fine when executed from directory: ./test.sh but when I try with “sh” command sh test.sh it’s not working:
test.sh: 3: test.sh: [[: not found
test.sh: 7: test.sh: [[: not found
Script:

#!/usr/bin/env bash

if [[ $1 = one ]]
        then
        printf "%b" "two\n" >&2
        exit 0
elif [[ $1 = two ]]
then
        printf "%b" "one\n" >&2
        exit 0
else
        printf "%b" "Specify argument: one/two\n"
        exit 1
fi

I goggled and found this link
Summary

sh is a different program than bash.

Detail

The problem is that the Bourne shell (sh) is not the Bourne Again shell (bash). Namely, sh doesn’t understand the [[ pragma. In fact, it doesn’t understand [ either. [ is an actual program or link to /bin/test (or /usr/bin/[, /usr/bin/test).

$ which [
/bin/[
$ ls -lh /bin/[
-r-xr-xr-x  2 root  wheel    42K Feb 29 17:11 /bin/[

When you execute your script directly through ./test.sh, you’re calling the script as the first argument to the program specified in the first line. In this case:
#!/usr/bin/env bash
Often, this is directly the interpreter (/bin/bash, or any number of other script interpreters), but in your case you’re using env to run a program in a modified environment — but that follow argument is still bash. Effectively, ./test.sh is bash test.sh.
Because sh and bash are different shells with different syntax interpretations, you’re seeing that error. If you run bash test.sh, you should see what is expected.
More info
Others have pointed out in comments that /bin/sh can be a link or other shell. Historically, sh was the Bourne shell on the old AT&T Unix, and in my mind the canonical descent. However, that is different in BSD variations and has diverged in other Unix based systems and distributions over time. If you’re really interested in the inner workings (including how /bin/sh and /bin/bash can be the same program and behave totally differently), read the following:
[1] [2]

As noted: /bin/sh typically (though not always) invokes a POSIX-compliant Bourne shell. Bash is Not Bourne.
Bash will attempt to emulate Bourne when invoked as ‘sh’ (as when /bin/sh symlinks or links to /bin/bash), or if $POSIXLY_CORRECT is defined in the invoking environment, when invoked with the –posix invocation option, or when ‘set -o posix’ has been executed. This enables testing a Bourne shell script / command for POSIX compliance.
Alternately, invoke scripts / test commands with a known POSIX-compliant shell. ‘dash’ is close, the Korn shell (ksh) IIRC offers a POSIX compliant option as well.

Date difference with Time in (Perl)

Function validateDateDifference() can validate date difference with time also.

Validation Range is from 1900-01-01 00:00:00 to 2199-12-31 23:59:59

Syntax

validateDateDifference(“Startdate time”,”Enddate time”,”dateformat”)

date format are : mmddyyyy or ddmmyyyy or yyyymmdd
(this function can support these time formats only)

Start date syntax : mm-dd-yyyy or dd-mm-yyyy or yyyy-mm-dd
you can replace “-” with “.” or “/”
for Ex. mm.dd.yyyy or mm/dd/yyyy
time syntax is : HH:MM:SS
EX. 19:10:59

Test cases :
validateDateDifference(“12.12.2013 12:12:58″,”12.12.2013 12:12:59″,”ddmmyyyy”)
validateDateDifference(“2013-01-31 12:12:58″,”2013-12-02 12:12:59″,”yyyymmdd”)

If you want to validate date only then you can use function validateDateFormat()

validateDateFormat(“date” , “dateformat”)

syntax same as above

If you want to validate time only then you can use function isvalidtime()

isvalidtime(“time”)

time syntax same as above


sub validateDateFormat{
$regexmmddyyyy='^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[- /.]((?:19|20|21)\d\d)$';
$regexddmmyyyy='^(0[1-9]|[12][0-9]|3[01])[-/.](0[1-9]|1[012])[- /.]((?:19|20|21)\d\d)$';
$regexyyyymmdd='^((?:19|20|21)\d\d)[- /.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])$';
$date=shift;
$format = shift;
if($format eq 'ddmmyyyy'){
if(eval $date=~$regexddmmyyyy){
$date = $1;
$month = $2;
$year = $3;
if(isvaliddate($date,$month,$year) eq "true"){
return $year.$month.$date; # Valid date
}else{
return "false"; # Not a valid date
}
}
}elsif($format eq 'mmddyyyy'){
if(eval $date=~$regexmmddyyyy){
$date = $2;
$month = $1;
$year = $3;
if(isvaliddate($date,$month,$year) eq "true"){
return $year.$month.$date; # Valid date
}else{
return "false"; # Not a valid date
}
}
}elsif($format eq 'yyyymmdd'){
if(eval $date=~$regexyyyymmdd){
$date = $3;
$month = $2;
$year = $1;
if(isvaliddate($date,$month,$year) eq "true"){
return $year.$month.$date; # Valid date
}else{
return "false"; # Not a valid date
}
}
}else{
return "false"; # Not a valid date
}
}
## HH:MM:SS is allowed only
sub isvalidtime{
$time = shift;
$regexhhmmss='^(0[1-9]|1[0-9]|2[0-3])[:](0[1-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])[:](0[1-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])$';
if(eval $time=~$regexhhmmss){
return "true";
}else{
return "false";
}
}
sub isvaliddate{
$date = shift;
$month = shift;
$year = shift;
#$date
#$month
#$year
if ($date == 31 and ($month == 4 or $month == 6 or $month == 9 or $month == 11)) {
return "false"; # 31st of a month with 30 days
}elsif ($date >= 30 and $month == 2) {
return "false"; # February 30th or 31st
} elsif ($month == 2 and $date == 29 and not ($year % 4 == 0 and ($year % 100 != 0 or $year % 400 == 0))) {
return "false"; # February 29th outside a leap year
} else {
return "true"; # Valid date
}
}
sub validateDateDifference{
$startdate = shift;
$enddate = shift;
$format =shift;
# Trimming dates and time " 20-01-2013 12.58.1 " --> "20-01-2013 12.59.32"
$startdate =~ s/^\s+|\s+$//g;
$enddate =~ s/^\s+|\s+$//g;
$format=~ s/^\s+|\s+$//g;
($startdate, $startdate_time) = split(/ +/, $startdate);
($enddate, $enddate_time) = split(/ +/, $enddate);
$startdate = validateDateFormat($startdate,$format);
if($startdate eq "false"){
return "false"; # invalid date difference
}
$enddate = validateDateFormat($enddate,$format);
if($enddate eq "false"){
return "false"; # invalid date difference
}
#converting into YYYYMMDD format
if($enddate == $startdate ){

if(isvalidtime($startdate_time) eq "false"){
print "reached";
return "false";
}
if(isvalidtime($enddate_time) eq "false"){
print "reached";
return "false";
}
$startdate_time =~ s/://g;
$enddate_time =~ s/://g;
if($startdate_time < $enddate_time){ return "true"; # Valid date difference }else{ return "false"; # invalid date difference } } elsif($enddate > $startdate ){
return "true"; # Valid date difference
}else{
return "false"; # invalid date difference
}
}
print 'validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","ddmmyyyy")\t'.validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","ddmmyyyy")."\n";
print 'validateDateDifference("12.12.2014 12:12:58","12.12.2014 12:12:12","ddmmyyyy")\t'.validateDateDifference("12.12.2014 12:12:58","12.12.2014 12:12:12","ddmmyyyy")."\n";
print 'validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmddyyyy")\t'.validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmddyyyy")."\n";
print 'validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmmmyyyy")\t'.validateDateDifference("12.12.2013 12:12:58","12.12.2013 12:12:59","mmmmyyyy")."\n";
print 'validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")\t'.validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")."\n";
print 'validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")\t'.validateDateDifference("2013-01-31 12:12:58","2013-12-02 12:12:59","yyyymmdd")."\n";