Skip to main content
deleted 9 characters in body
Source Link
Gilles Quénot
  • 36.7k
  • 7
  • 74
  • 97

The properA way, in : if you want to know if there's some files matching the pattern *.txt, then consider:

(
    shopt -s nullglob
    compgen -W *.txt &>/dev/null

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

The proper way, in : if you want to know if there's some files matching the pattern *.txt, then consider:

(
    shopt -s nullglob
    compgen -W *.txt &>/dev/null

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

A way, in : if you want to know if there's some files matching the pattern *.txt, then consider:

(
    shopt -s nullglob
    compgen -W *.txt &>/dev/null

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

added 12 characters in body
Source Link
Gilles Quénot
  • 36.7k
  • 7
  • 74
  • 97

The proper way, in : if you want to know if there's some files matching the pattern *.txt, then consider:

(
    shopt -s nullglob
    compgen -W *.txt &>/dev/null

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

The proper way, in : if you want to know if there's some files matching the pattern *.txt, then consider:

(
    shopt -s nullglob
    compgen -W *.txt

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

The proper way, in : if you want to know if there's some files matching the pattern *.txt, then consider:

(
    shopt -s nullglob
    compgen -W *.txt &>/dev/null

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

added 89 characters in body
Source Link
Gilles Quénot
  • 36.7k
  • 7
  • 74
  • 97

The proper way, in : if you want to know if there's some files matching the pattern *.txt in , then consider:

(
    shopt -s nullglob
    compgen -W *.txt

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

The proper way: if you want to know if there's some files matching the pattern *.txt in , then consider:

(
    shopt -s nullglob
    compgen -W *.txt

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings

The proper way, in : if you want to know if there's some files matching the pattern *.txt, then consider:

(
    shopt -s nullglob
    compgen -W *.txt

    case $? in
        0) echo 'one match' ;;
        1) echo 'more than one match' ;;
        3) echo 'no match at all' ;;
    esac
)

The subshell ( ) is here only to reset shopt as default settings. Can use

shopt -u nullglob 

too.

Note

It's different than compgen -G, because here we can discriminates more cases

Source Link
Gilles Quénot
  • 36.7k
  • 7
  • 74
  • 97
Loading