Home > Enterprise >  Mac run mysql command in .sh file
Mac run mysql command in .sh file

Time:11-04

I want to execute a mysql command from a test.sh file. My file looks like this:

#!/bin/zsh

mysql -u 'USERNAME' -p 'PASSWORD' -h 'localhost' --port='9999'

When I run it in the Terminal I get:

test.sh:3: command not found: mysql

I have defined an alias for the mysql command in .zshrc and .bashrc file:

alias mysql=/Applications/MAMP/Library/bin/mysql

Interesting enough I can run/connect to mysql in the terminal and it works. I have installed mysql with MAMP and I am using MacOS Ventura 13.0.

Any idea what's going on here?

CodePudding user response:

.zshrc is read only when starting interactive shells, not shells run for scripts. See https://unix.stackexchange.com/questions/71253/what-should-shouldnt-go-in-zshenv-zshrc-zlogin-zprofile-zlogout

You can put initialization code into .zshenv, which is read when starting any zsh process.

  • Related