Launching commands in separate windows using bash

How can I launch commands in new terminal windows? I've tried the below

#!/bin/bash
open -a Terminal "" -e "/usr/local/bin/zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties"
open -a Terminal "" -e "/usr/local/bin/kafka-server-start /usr/local/etc/kafka/server.properties"

However I get

the file /usr/local/bin/kafka-server-start /usr/local/etc/kafka/server.properties does not exist.

The file does exist: e.g. ls /usr/local/bin/kafka-server-start shows that the file is in there.

How can I tell it that the properities file is a parameter and not part of the path? Assuming this is the correct way to open a terminal with a new command.

I'm on MacOS Catalina, if it helps.


Solution 1:

This is what you're looking for:

#!/bin/bash
osascript -e 'tell application "Terminal"' -e 'do script "/usr/local/bin/zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties"' -e 'do script "/usr/local/bin/kafka-server-start /usr/local/etc/kafka/server.properties"' -e 'end tell'

It can also be done as:

#!/bin/bash
osascript <<-EOF 
tell application "Terminal"
    do script "/usr/local/bin/zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties"
    do script "/usr/local/bin/kafka-server-start /usr/local/etc/kafka/server.properties"
end tell
EOF

Or like so:

#!/usr/bin/osascript

tell application "Terminal"
    do script "/usr/local/bin/zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties"
    do script "/usr/local/bin/kafka-server-start /usr/local/etc/kafka/server.properties"
end tell