Can't open input file: zsh
Asked Answered
zsh
L

4

5

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!

Lemonade answered 18/10, 2021 at 1:32 Comment(1)
whats the output of ls -ltr and what command are you using to run it?Karlsruhe
C
5

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.

Costly answered 18/10, 2021 at 6:19 Comment(3)
Thanks for mentioning this! I think I may be running into macOS TCC policy you mentioned. I have a folder within the ~/Downloads folder where I'm trying to run a script from but somehow see this error. Is there something else I can do? Moving it into yet another folder doesn't seem to help in my case :/ Thanks!Kusin
In my case, when I use a full path rather navigating to the script's directory with cd "$(dirname "$0")" it works. I guess that will be a workaround for now, but not ideal since I can't move my scripts around to a different location. If there's another possible solution, please let me know.Kusin
Figured it out for ZSH on Mac! To get scripts to run from any relative directory, you can just append the rest of the path to the front of the script name: BASEDIR=$(dirname "$0"); echo "Script location: ${BASEDIR}"; cd "$(dirname "$0")"; $BASEDIR/<script_name>.command; Since this may help others I'll post it as a separate answer as well.Kusin
K
1

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)

Kusin answered 10/3, 2022 at 16:34 Comment(0)
O
0

I moved my main script to /opt/scripts

Then I choose to give bash and my application that needs it "Full Disk Access" or more selectively under "Files and Folder" the appropriate permissions

See Settings -> Privacy & Security -> Files and Folder / Full Disk Access

enter image description here

Oren answered 20/1 at 13:37 Comment(0)
B
0

Figured it out! This is happening because the cron binary doesn't have the permission to access the Desktop folder you can solve it by giving the access to desktop or full disk access to cron binary from system preferences the location of the cron binary on mac is in /usr/sbin

cmd+shift+G to go to the folder while in the system preferences

This should work perfectly

Biologist answered 11/10 at 5:37 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Sum

© 2022 - 2024 — McMap. All rights reserved.