Skip to content

Instantly share code, notes, and snippets.

@rawiriblundell
Created November 13, 2019 06:25
Show Gist options
  • Save rawiriblundell/7bb259050e84e9083b43836b2387e18f to your computer and use it in GitHub Desktop.
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
# 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