I found a non-interactive solution to run bash commands for a certain local site 
Here’s the bash script for that - just make sure to start the local site before running it:
#!/bin/bash
# Runs some WP CLI commands inside a local site.
run_in_local_site() {
# The $SHELL variable needs to be empty; otherwise the local
# ssh-entry script will start a new, interactive shell
# process (not a sub-shell!)
SHELL=""
# Set up the LocalWP environment.
source "~/Library/Application\ Support/Local/ssh-entry/$1" \
&>/dev/null
# Finally, we have a "ssh" environment that allows us to
# directly interact with the local site. We can run our
# commands here:
wp option get siteurl
}
The above function loads the LocalWP environment for a specified site and then runs one wp-cli command (just an example) - the site is specified by the $1
variable, which is the first parameter of the function:
# Important: Run the command in a sub-shell!
# Otherwise the LocalWP settings will spill over to the current
# shell process (and change $SHELL, etc)...
$(run_in_local_site O3hzP9siT.sh)
$(run_in_local_site Bi2Hj9eod.sh)
Instead of using a custom function (run_in_local_site
) you could also shorten the code to a 1-liner, like this:
#!/bin/bash
echo $(SHELL= && source ~/Library/Application\ Support/Local/ssh-entry/O3hzP9siT.sh &>/dev/null && wp option get siteurl)