Terminal won't find command of custom script since Catalina update

I have a very simple script to hide the icons from my desktop

#!/usr/bin/env bash
defaults write com.apple.finder CreateDesktop false
killall Finder

It is located in $USER/bin. Since the update, when I try to execute it using only the name of the script as a command, it doesn't work, the error being zsh: command not found: icon. Same for the other script located in the same folder. If I execute the script by double clicking, it works.


Solution 1:

The directory ~/bin/ (e.g. /Users/alice/bin) is no standard path for executables. It has to be added to the PATH variable.

After changing the default login-shell from bash (-10.14) to zsh (10.15-) any customizations of the PATH-variable in .bash_profile/.profile/.bashrc to add custom directories (e.g. export PATH=/Users/alice/bin:$PATH) or other variables (and aliases etc.) won't work anymore in your login-shell.

But you can simply create/modify a similar file for zsh (.zprofile/.zshrc):

touch .zprofile
echo 'export PATH=/Users/alice/bin:$PATH' >> ~/.zprofile

Personally I soft-linked .zshrc to .zprofile:

ln -s ~/.zprofile ~/.zshrc

Afterwards either source this file or close and reopen the Terminal window to make the changes of the PATH variable effective.