写了一个脚本,想用 Mac 的 launchctl 守护进程开机执行。脚本如下:
#!/bin/zsh
fswatch /code | while read file
do
~upto
done
大致功能是用 fswatch
命令监听文件修改动作,有文件被修改就执行脚本。
fswatch
是用 brew install fswatch
命令安装的,单独执行 fswatch
命令或者执行上述脚本都没有问题。
但是写了一个 launchctl 守护进程脚本:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.fswatch</string>
<key>Program</key>
<string>/xxx/fswatch.sh</string>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>fswatch-plist.log</string>
<key>StandardErrorPath</key>
<string>fswatch-plist.err</string>
</dict>
</plist>
查看fswatch-plist.err 发现报错:fswatch.sh:2: command not found: fswatch
为什么找不到命令呢?我尝试把该命令所在路径 /opt/homebrew/bin
加入系统环境变量,依然找不到,求解。