Can't open input file: zsh

Viewed 3107

I'm trying to execute a .zsh script on Macos big sur and it's not letting me.

Whenever I run the .zsh in terminal, it says "/bin/zsh: can't open input file: file-name.zsh"

I already did brew install zsh prior to this so I'm a bit confused.

Any help would be greatly appreciated. Thanks!

2 Answers

In macOS Transparency Consent and Control (TCC) restricts access to "personal" data, including anything in a user's Desktop folder and outputs a /bin/zsh: can't open input file error message if you try to disobey this rule. Try moving file-name.zsh to a different folder, and if moving file-name.zsh to another folder doesn't help refer to file-name.zsh by using the full path to file-name.zsh.

Figured it out for ZSH on Mac! To get scripts to run from any relative directory, you can first append the rest of the path to the front of the script name and then run as usual:

BASEDIR=$(dirname "$0")
echo "Script location: ${BASEDIR}"
cd "$(dirname "$0")"

$BASEDIR/<script_name>.command

This is currently working for me on macOS Monterey.

(Copied from comment to Karel's answer about macOS ZSH + TCC policy)

Related