3 ms·
Recent versions of Bash don't expand the * (et cetera) patterns when there is no match, which although sometimes useful, I still feel it's a hack.
by amelius 2y ago
Recent versions of Bash don't expand the * (et cetera) patterns when there is no match, which although sometimes useful, I still feel it's a hack.
- Joker_vD 2y agoThat's been around since the original Bourne shell; /etc/glob, from what I can see from its source, would refuse to run the command if the resulting expansion turned out completely empty; and the globs with no matches would be simply removed.
- amelius 2y agoThat's not how it works in recent Ubuntu releases. If there is no match, the command runs with the wildcard chars not substituted. # echo foo*bar foo*bar
- Joker_vD 2y agoYes, this current behaviour was introduced by the original Bourne shell and then it stuck for some silly reason or another (it probably has some fringe use cases but they elude me). Thompson's original shell, or rather, /etc/glob, at various versions implemented the mix of behaviours that would later be reintroduced as nullglob and failglob options in Bash.
- pwg 2y agoThe action to take upon no match is configurable in recent Bash versions. The 'failglob' shopt option will cause an error to be generated if a glob matches nothing. The 'nullglob' shopt option toggles between no match expanding to an empty string and the traditional default of no match leaving the glob characters untouched.