5 comments

[ 3.3 ms ] story [ 22.7 ms ] thread
Windows CMD is often criticized, but it is easier to work with in at least one way. A task discussed in the post, to find a file with name containing "meta" in a subdirectory is just dir /b /s *meta* .
Using find:

  find . -name '*meta*'
If you want to use the matching files on a command line (requires "shopt -s globstar")

    some_command **/*meta*
The double star expands to any number of directories. You can even mix-and-match complex patterns as needed:

    some_command */data/**/*meta*
    # matches:
    #   dir_a/data/meta
    #   dir_b/data/foo/bar/baz/meta.txt
WARNING:

The source for this script is very strange; it looks like the output of a minifier/obfuscator, or otherwise machine generated. The entire script uses single character variable names, and most expressions have all optional whitespace removed.

Regardless of the "minified" style, the source is also missing double quotes on approximately 80% of variable expansions. The special variable expansion $@ and its array equivalent ${arr[@]} are regularly used unquoted, which does NOT preserve word splitting boundaries across whitespace like the $* ; this will cause bugs!

Shellcheck [1] has a lot of issues with this script. You might consider refactoring it a little bit to pass without errors. Some of the warnings could probably be ignored.

[1] - https://www.shellcheck.net/