I know you can use the find
command for this simple job, but I got an assignment not to use find
or ls
and do the job. How can I do th
Based on this answer; use shell options for the desired globbing behaviour:
**
with globstar
(Bash 4.0 or newer)dotglob
**/*/
if there is no match with nullglob
and then use printf with the %q formatting directive to quote directory names with special characters in them:
shopt -s globstar dotglob nullglob
printf '%q\n' **/*/
so if you have directories like has space
or even containing a newline, you'd get output like
$ printf '%q\n' **/*/
$'has\nnewline/'
has\ space/
with one directory per line.