I am trying to accomplish something that is easy in bash: look for files in a folder and source them if they exist (and do not output if no files exist).
In bourne shells this is how to do it:
if [ -d /etc/profile.d ]; then for f in `ls -1 /etc/profile.d/*.sh 2> /dev/null`; do . $f done fi
I am new to zsh and cannot get the equivalent working. What am I doing wrong?
if [[ -d "/etc/zsh.d" ]]; then for file in (ls -1 /etc/zsh.d/*.zsh 2> /dev/null); do source $file done fi
fail: parse error near '>'
.
I have tried many variations and cannot get it to be as smooth as the sh/bash equivalent. It's as if redirection does not always work within subshells.