I wrote a simple script for generating aliases in zsh shell. Here it is:
for subject in $(find $path -maxdepth 2 -type d -print)
do
dir=$(printf -- "$subject\n" | sed 's|.*/||')
alias "$dir"="cd $subject"
done
It is pretty self-explanatory - recurses through a directory to up to 2 levels, and lists every directory found. Later, it uses that directory name as an alias for changing directory.
Somewhat predictably, it doesn't work. Aliases remain "encapsulated" within the script. For the record, when I execute these script lines in shell, everything works fine.
Thanks in advance.
for $subject in
, that should befor subject in
. Also, as a general rule, avoid usingfor
loops for things like that, it will break if any results contain spaces, let alone harder things like newlines. See http://mywiki.wooledge.org/DontReadLinesWithFor – terdon May 06 '21 at 11:10bash
shell, notzsh
. The two shells work the same with regards to the issue in this question though. – Kusalananda May 06 '21 at 11:26