Created
November 13, 2019 06:25
-
-
Save rawiriblundell/7bb259050e84e9083b43836b2387e18f to your computer and use it in GitHub Desktop.
Do not parse the output of ls within scripts. So... how do you list just directories then? Here's how
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note that this uses the 'func() ( ;)' form, not 'func() { ;}' | |
# in order to contain any changes to dotglob or nullglob | |
# This means that this function will also return directories | |
# whose names begin with a dot. | |
listdirs() ( | |
shopt -s dotglob nullglob | |
set -- */ | |
printf -- '%s\n' "${@%/}" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment