Search code examples
bashmacosshellterminalglob

Bash glob pattern behaviour different between terminal and shell script


I have a glob pattern {,**/}*.* for recursing through all files in current directory plus children. In the terminal if I run echo {,**/}*.* it outputs all of the files in the current directory plus the nested directories. When I run a shell script which contains this line it only does one directory deep.

I understand that terminal has different behaviour than the shell: adding shopt -s extglob made no difference.

#!/bin/bash

shopt -s extglob
echo {,**/}*.*

I am on MacOSX with Bash 4 terminal and shopt -s globstar enabled.


Solution

  • Thanks @Aserre and @anubhava, it was indeed the combination of bash path and making sure globstar was enabled (for MacOSX). Full script is:

    #!/usr/local/bin/bash
    
    shopt -s globstar
    
    echo {,**/}*.*
    

    And yes ./** would suffice but that wasn't my problem :)