Skip to main content
"whatever" is the filename for which the first test will really pass
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272

There are some subtle differences though:

#!/bin/bash

eg=whatever

if [ $eg == what* ]; then   # file glob test
    echo '[]'
fi

if [[ $eg == what* ]]; then   # pattern match test
    echo "[[]]"
fi      

Unless there is a file called "whatever" in the current directory, the first test will not pass, because the match is against a file glob of the current directory contents, whereas the second one is an actual string pattern match.

There are some subtle differences though:

#!/bin/bash

eg=whatever

if [ $eg == what* ]; then   # file glob test
    echo '[]'
fi

if [[ $eg == what* ]]; then   # pattern match test
    echo "[[]]"
fi      

Unless there is a file called "whatever" in the current directory, the first test will not pass.

There are some subtle differences though:

#!/bin/bash

eg=whatever

if [ $eg == what* ]; then   # file glob test
    echo '[]'
fi

if [[ $eg == what* ]]; then   # pattern match test
    echo "[[]]"
fi      

Unless there is a file called "whatever" in the current directory, the first test will not pass, because the match is against a file glob of the current directory contents, whereas the second one is an actual string pattern match.

"whatever" is the filename for which the first test will really pass
Source Link

There are some subtle differences though:

#!/bin/bash

eg=whatever

if [ $eg == what* ]; then   # file glob test
    echo '[]'
fi

if [[ $eg == what* ]]; then   # pattern match test
    echo "[[]]"
fi      

Unless there is a file called "what[something]""whatever" in the current directory, the first test will not pass.

There are some subtle differences though:

#!/bin/bash

eg=whatever

if [ $eg == what* ]; then   # file glob test
    echo '[]'
fi

if [[ $eg == what* ]]; then   # pattern match test
    echo "[[]]"
fi      

Unless there is a file called "what[something]" in the current directory, the first test will not pass.

There are some subtle differences though:

#!/bin/bash

eg=whatever

if [ $eg == what* ]; then   # file glob test
    echo '[]'
fi

if [[ $eg == what* ]]; then   # pattern match test
    echo "[[]]"
fi      

Unless there is a file called "whatever" in the current directory, the first test will not pass.

Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272

There are some subtle differences though:

#!/bin/bash

eg=whatever

if [ $eg == what* ]; then   # file glob test
    echo '[]'
fi

if [[ $eg == what* ]]; then   # pattern match test
    echo "[[]]"
fi      

Unless there is a file called "what[something]" in the current directory, the first test will not pass.