Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 505
mummybot Avatar asked Sep 18 '26 18:09

mummybot


1 Answers

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 :)

like image 53
mummybot Avatar answered Sep 21 '26 10:09

mummybot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!